<?php
ob_start();
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Manage_Event extends CI_Controller {
	public function __construct()
	{
		parent::__construct();
		
		$this->output->set_header('Last-Modified:'.gmdate('D, d M Y H:i:s').'GMT');
		$this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate');
		$this->output->set_header('Cache-Control: post-check=0, pre-check=0',false);
		$this->output->set_header('Pragma: no-cache');
		$this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
		$this->allowed =array('admin', 'panelist');
		
		#load all database and required models
		$this->load->database();
		$this->load->model('common_model');
		$this->load->model('event_model');
		$this->load->model('admin_model');
		
		$this->data = array();
		$this->data['admin_value'] = $this->session->all_userdata();
		if($this->data['admin_value']['admin_type'] == 'Web Admin' || $this->data['admin_value']['admin_type'] == 'Sub Admin')
		{
			$this->admin = 'admin';
		}
		else {
			$this->admin = 'panelist';
		}
	}

	public function createEvent($value='')
	{
		if($this->session->userdata('admin_id') && $this->session->userdata('admin_id') != '' && $this->session->userdata('logedin'))
		{
			if(!in_array($value, $this->allowed))
			{
				header('Location: '.BASE_URL.'/'.$this->admin.'/dashboard');
				redirect(BASE_URL.'/'.$this->admin.'/dashboard');
				exit();
			}

			$this->session->set_userdata('select_event_tab', 'main');
			
			if($this->input->post('eventname'))
			{
				// Set validation rules.
				$this->form_validation->set_rules('eventname', 'Event Name','trim|required|xss_clean');
				$this->form_validation->set_rules('description', 'Event Description','trim|required|xss_clean');
				$this->form_validation->set_rules('category', 'Event Category','trim|xss_clean');
				// Run the validation.
				if ($this->form_validation->run())
				{
					$this->data['post_value'] = $this->input->post();
					if($this->event_model->checkEvent($this->data['post_value']['eventname']))
					{
						$this->data['error']='Event already exists';
						$this->data['application_form_personal'] = $this->event_model->getAllFormField('application','Personal','Applicant Particulars');
						$this->data['application_form_contact'] = $this->event_model->getAllFormField('application','Contact','Applicant Particulars');
						$this->data['application_form_extra'] = $this->event_model->getAllFormField('application','Extra','Applicant Particulars');
						$this->data['application_education_pg'] = $this->event_model->getAllFormField('application','Postgraduate','Educational Background');
						$this->data['application_education_phd'] = $this->event_model->getAllFormField('application','PhD','Educational Background');
						$this->data['application_education_master'] = $this->event_model->getAllFormField('application','Masters','Educational Background');
						$this->data['application_education_extra'] = $this->event_model->getAllFormField('application','Extra','Educational Background');
						$this->data['application_form_docs'] = $this->event_model->getAllFormField('application','Documents','');
						
						$this->data['nomination_form_personal'] = $this->event_model->getAllFormField('nomination','Nominee Personal','Nominee');
						$this->data['nomination_form_contact'] = $this->event_model->getAllFormField('nomination','Nominee Contact','Nominee');
						$this->data['nomination_form_extra'] = $this->event_model->getAllFormField('nomination','Nominee Extra','Nominee');
						$this->data['nomination_form_nominant'] = $this->event_model->getAllFormField('nomination','Nominating Personal','Nominating Party');
						$this->data['nomination_form_nominant_extra'] = $this->event_model->getAllFormField('nomination','Nominating Extra','Nominating Party');
						$this->data['nomination_form_disclosure'] = $this->event_model->getAllFormField('nomination','','Disclosure Notice');
						$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
						$this->load->view('admin/manage_event/create_event',$this->data);
						
					}
					else
					{
						$val = $this->event_model->addEvent($this->data['post_value']);
						if($val > 0)
						{
							$this->session->set_userdata('event_success', 'Event added successfully. Create Aplication / Nomination Forms.');
							header('Location: '.BASE_URL.'/'.$this->admin.'/create_event');
							redirect(BASE_URL.'/'.$this->admin.'/create_event');
							exit();
						}
						else
						{
							$this->data['error']='Problem in creating Event';
							$this->data['application_form_personal'] = $this->event_model->getAllFormField('application','Personal','Applicant Particulars');
							$this->data['application_form_contact'] = $this->event_model->getAllFormField('application','Contact','Applicant Particulars');
							$this->data['application_form_extra'] = $this->event_model->getAllFormField('application','Extra','Applicant Particulars');
							$this->data['application_education_pg'] = $this->event_model->getAllFormField('application','Postgraduate','Educational Background');
							$this->data['application_education_phd'] = $this->event_model->getAllFormField('application','PhD','Educational Background');
							$this->data['application_education_master'] = $this->event_model->getAllFormField('application','Masters','Educational Background');
							$this->data['application_education_extra'] = $this->event_model->getAllFormField('application','Extra','Educational Background');
							$this->data['application_form_docs'] = $this->event_model->getAllFormField('application','Documents','');
							
							$this->data['nomination_form_personal'] = $this->event_model->getAllFormField('nomination','Nominee Personal','Nominee');
							$this->data['nomination_form_contact'] = $this->event_model->getAllFormField('nomination','Nominee Contact','Nominee');
							$this->data['nomination_form_extra'] = $this->event_model->getAllFormField('nomination','Nominee Extra','Nominee');
							$this->data['nomination_form_nominant'] = $this->event_model->getAllFormField('nomination','Nominating Personal','Nominating Party');
							$this->data['nomination_form_nominant_extra'] = $this->event_model->getAllFormField('nomination','Nominating Extra','Nominating Party');
							$this->data['nomination_form_disclosure'] = $this->event_model->getAllFormField('nomination','','Disclosure Notice');
							$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
							$this->load->view('admin/manage_event/create_event',$this->data);
						}
					}
				}
				else
				{
					$this->data['post_value'] = $this->input->post();	
					$this->data['error'] = validation_errors();
					$this->data['application_form_personal'] = $this->event_model->getAllFormField('application','Personal','Applicant Particulars');
					$this->data['application_form_contact'] = $this->event_model->getAllFormField('application','Contact','Applicant Particulars');
					$this->data['application_form_extra'] = $this->event_model->getAllFormField('application','Extra','Applicant Particulars');
					$this->data['application_education_pg'] = $this->event_model->getAllFormField('application','Postgraduate','Educational Background');
					$this->data['application_education_phd'] = $this->event_model->getAllFormField('application','PhD','Educational Background');
					$this->data['application_education_master'] = $this->event_model->getAllFormField('application','Masters','Educational Background');
					$this->data['application_education_extra'] = $this->event_model->getAllFormField('application','Extra','Educational Background');
					$this->data['application_form_docs'] = $this->event_model->getAllFormField('application','Documents','');
					
					$this->data['nomination_form_personal'] = $this->event_model->getAllFormField('nomination','Nominee Personal','Nominee');
					$this->data['nomination_form_contact'] = $this->event_model->getAllFormField('nomination','Nominee Contact','Nominee');
					$this->data['nomination_form_extra'] = $this->event_model->getAllFormField('nomination','Nominee Extra','Nominee');
					$this->data['nomination_form_nominant'] = $this->event_model->getAllFormField('nomination','Nominating Personal','Nominating Party');
					$this->data['nomination_form_nominant_extra'] = $this->event_model->getAllFormField('nomination','Nominating Extra','Nominating Party');
					$this->data['nomination_form_disclosure'] = $this->event_model->getAllFormField('nomination','','Disclosure Notice');
					$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
					$this->load->view('admin/manage_event/create_event',$this->data);
				}
			}
			else if($this->input->post('form_type') && $this->input->post('form_type') == 'Application')
			{
				
				// Set validation rules.
				$this->form_validation->set_rules('choose_event', 'Choose Event','trim|required|xss_clean');
				$this->form_validation->set_rules('activation_status', 'Activation Status','trim|required|xss_clean');
				$this->form_validation->set_rules('form_header', 'Form Header','trim|xss_clean');
				$this->form_validation->set_rules('form_footer', 'Form Footer','trim|xss_clean');
				$this->form_validation->set_rules('thanks_page', 'Thankyou Page','trim|xss_clean');
				$this->form_validation->set_rules('decline_page', 'Decline Page','trim|xss_clean');
				
				$this->form_validation->set_rules('ap_field1', 'First Name','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field3', 'Last Name','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field4', 'Nationality','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field5', 'Country of Residence','trim|required|xss_clean');
				//$this->form_validation->set_rules('ap_field6', 'Gender','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field9', 'Date of Birth','trim|required|xss_clean');
				//$this->form_validation->set_rules('ap_field10', 'Place of Birth','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field11', 'Telephone','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field13', 'Correspondence Address','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field14', 'Postal Code','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field15', 'State/Province','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field16', 'Country','trim|required|xss_clean');
				for($i=19;$i<=38;$i++)
				{
					if($this->input->post('ap_field'.$i.'_text') && $this->input->post('ap_field'.$i.'_text') != '')
					{
						$this->form_validation->set_rules('ap_field'.$i.'_text', $this->input->post('ap_field'.$i.'_text'),'trim');
					}
				}
				for($n=53;$n<=72;$n++)
				{
					if($this->input->post('ap_field'.$n.'_text') && $this->input->post('ap_field'.$n.'_text') != '')
					{
						$this->form_validation->set_rules('ap_field'.$n.'_text', $this->input->post('ap_field'.$n.'_text'),'trim|xss_clean');
					}
				}
				// Run the validation.
				if ($this->form_validation->run())
				{
					$this->data['post_value'] = $this->input->post();
					if($this->event_model->checkEventForm($this->data['post_value']['choose_event']))
					{
						$this->data['error']='Application Form for this event already exists';
						$this->data['application_form_personal'] = $this->event_model->getAllFormField('application','Personal','Applicant Particulars');
						$this->data['application_form_contact'] = $this->event_model->getAllFormField('application','Contact','Applicant Particulars');
						$this->data['application_form_extra'] = $this->event_model->getAllFormField('application','Extra','Applicant Particulars');
						$this->data['application_education_pg'] = $this->event_model->getAllFormField('application','Postgraduate','Educational Background');
						$this->data['application_education_phd'] = $this->event_model->getAllFormField('application','PhD','Educational Background');
						$this->data['application_education_master'] = $this->event_model->getAllFormField('application','Masters','Educational Background');
						$this->data['application_education_extra'] = $this->event_model->getAllFormField('application','Extra','Educational Background');
						$this->data['application_form_docs'] = $this->event_model->getAllFormField('application','Documents','');
						
						$this->data['nomination_form_personal'] = $this->event_model->getAllFormField('nomination','Nominee Personal','Nominee');
						$this->data['nomination_form_contact'] = $this->event_model->getAllFormField('nomination','Nominee Contact','Nominee');
						$this->data['nomination_form_extra'] = $this->event_model->getAllFormField('nomination','Nominee Extra','Nominee');
						$this->data['nomination_form_nominant'] = $this->event_model->getAllFormField('nomination','Nominating Personal','Nominating Party');
						$this->data['nomination_form_nominant_extra'] = $this->event_model->getAllFormField('nomination','Nominating Extra','Nominating Party');
						$this->data['nomination_form_disclosure'] = $this->event_model->getAllFormField('nomination','','Disclosure Notice');
						$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
						$this->form_validation->unset_field_data();
						$this->load->view('admin/manage_event/create_event',$this->data);
					}
					else
					{
						$val = $this->event_model->editEventForm($this->data['post_value']);
						if($val > 0)
						{
							if(isset($this->data['post_value']['form_type']) && $this->data['post_value']['form_type']!=''){
								$this->session->set_userdata('event_success', $this->data['post_value']['form_type'].' form created successfully.');
							}
							else {
								$this->session->set_userdata('event_success', 'Form created successfully.');
							}
							header('Location: '.BASE_URL.'/'.$this->admin.'/create_event');
							redirect(BASE_URL.'/'.$this->admin.'/create_event');
							exit();
						}
						else
						{
							$this->data['error']='Problem in creating event application form';
							$this->data['application_form_personal'] = $this->event_model->getAllFormField('application','Personal','Applicant Particulars');
							$this->data['application_form_contact'] = $this->event_model->getAllFormField('application','Contact','Applicant Particulars');
							$this->data['application_form_extra'] = $this->event_model->getAllFormField('application','Extra','Applicant Particulars');
							$this->data['application_education_pg'] = $this->event_model->getAllFormField('application','Postgraduate','Educational Background');
							$this->data['application_education_phd'] = $this->event_model->getAllFormField('application','PhD','Educational Background');
							$this->data['application_education_master'] = $this->event_model->getAllFormField('application','Masters','Educational Background');
							$this->data['application_education_extra'] = $this->event_model->getAllFormField('application','Extra','Educational Background');
							$this->data['application_form_docs'] = $this->event_model->getAllFormField('application','Documents','');
							
							$this->data['nomination_form_personal'] = $this->event_model->getAllFormField('nomination','Nominee Personal','Nominee');
							$this->data['nomination_form_contact'] = $this->event_model->getAllFormField('nomination','Nominee Contact','Nominee');
							$this->data['nomination_form_extra'] = $this->event_model->getAllFormField('nomination','Nominee Extra','Nominee');
							$this->data['nomination_form_nominant'] = $this->event_model->getAllFormField('nomination','Nominating Personal','Nominating Party');
							$this->data['nomination_form_nominant_extra'] = $this->event_model->getAllFormField('nomination','Nominating Extra','Nominating Party');
							$this->data['nomination_form_disclosure'] = $this->event_model->getAllFormField('nomination','','Disclosure Notice');
							$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
							$this->form_validation->unset_field_data();
							$this->load->view('admin/manage_event/create_event',$this->data);
						}
					}
				}
				else
				{
						$this->data['post_value'] = $this->input->post();	
						$this->data['error'] = validation_errors();
						$this->data['application_form_personal'] = $this->event_model->getAllFormField('application','Personal','Applicant Particulars');
						$this->data['application_form_contact'] = $this->event_model->getAllFormField('application','Contact','Applicant Particulars');
						$this->data['application_form_extra'] = $this->event_model->getAllFormField('application','Extra','Applicant Particulars');
						$this->data['application_education_pg'] = $this->event_model->getAllFormField('application','Postgraduate','Educational Background');
						$this->data['application_education_phd'] = $this->event_model->getAllFormField('application','PhD','Educational Background');
						$this->data['application_education_master'] = $this->event_model->getAllFormField('application','Masters','Educational Background');
						$this->data['application_education_extra'] = $this->event_model->getAllFormField('application','Extra','Educational Background');
						$this->data['application_form_docs'] = $this->event_model->getAllFormField('application','Documents','');
						
						$this->data['nomination_form_personal'] = $this->event_model->getAllFormField('nomination','Nominee Personal','Nominee');
						$this->data['nomination_form_contact'] = $this->event_model->getAllFormField('nomination','Nominee Contact','Nominee');
						$this->data['nomination_form_extra'] = $this->event_model->getAllFormField('nomination','Nominee Extra','Nominee');
						$this->data['nomination_form_nominant'] = $this->event_model->getAllFormField('nomination','Nominating Personal','Nominating Party');
						$this->data['nomination_form_nominant_extra'] = $this->event_model->getAllFormField('nomination','Nominating Extra','Nominating Party');
						$this->data['nomination_form_disclosure'] = $this->event_model->getAllFormField('nomination','','Disclosure Notice');
						$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
						$this->form_validation->unset_field_data();
						$this->load->view('admin/manage_event/create_event',$this->data);
				}
			}
			else if($this->input->post('form_type') && $this->input->post('form_type') == 'Nomination')
			{
				// Set validation rules.
				$this->form_validation->set_rules('choose_event1', 'Choose Event','trim|required|xss_clean');
				$this->form_validation->set_rules('activation_status1', 'Activation Status','trim|required|xss_clean');
				$this->form_validation->set_rules('form_header1', 'Form Header','trim|xss_clean');
				$this->form_validation->set_rules('form_footer1', 'Form Footer','trim|xss_clean');
				$this->form_validation->set_rules('thanks_page1', 'Thankyou Page','trim|xss_clean');
				$this->form_validation->set_rules('decline_page1', 'Decline Page','trim|xss_clean');
				
				$this->form_validation->set_rules('nom_field1', 'Nominee\'s First Name','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field3', 'Nominee\'s Last Name','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field4', 'Nationality','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field5', 'Country of Residence','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field11', 'Telephone','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field13', 'Correspondence Address','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field14', 'Postal Code','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field15', 'State/Province','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field16', 'Country','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field16', 'Email','trim|required|xss_clean');
				for($i=19;$i<=24;$i++)
				{
					//var_dump('test'); die();
					if($this->input->post('nom_field'.$i.'_text') && $this->input->post('nom_field'.$i.'_text') != '')
					{
						$this->form_validation->set_rules('nom_field'.$i.'_text', $this->input->post('nom_field'.$i.'_text'),'trim|xss_clean');
					}
				}
				$this->form_validation->set_rules('nom_field25', 'Nominator\'s First Name','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field27', 'Nominator\'s Last Name','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field28', 'Nominator\'s Position','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field29', 'Nominator\'s Institution Affiliation','trim|required|xss_clean');
				//$this->form_validation->set_rules('nom_field32', 'Nominator\'s Email','trim|required|xss_clean');
				for($i=34;$i<=39;$i++)
				{
					if($this->input->post('nom_field'.$i.'_text') && $this->input->post('nom_field'.$i.'_text') != '')
					{
						$this->form_validation->set_rules('nom_field'.$i.'_text', $this->input->post('nom_field'.$i.'_text'),'trim|xss_clean');
					}
				}
				// Run the validation.
				if ($this->form_validation->run())
				{
					$this->data['post_value'] = $this->input->post();
					if($this->event_model->checkEventNominationForm($this->data['post_value']['choose_event1']))
					{
						$this->data['error']='Nomination Form for this event already exists';
						$this->data['application_form_personal'] = $this->event_model->getAllFormField('application','Personal','Applicant Particulars');
						$this->data['application_form_contact'] = $this->event_model->getAllFormField('application','Contact','Applicant Particulars');
						$this->data['application_form_extra'] = $this->event_model->getAllFormField('application','Extra','Applicant Particulars');
						$this->data['application_education_pg'] = $this->event_model->getAllFormField('application','Postgraduate','Educational Background');
						$this->data['application_education_phd'] = $this->event_model->getAllFormField('application','PhD','Educational Background');
						$this->data['application_education_master'] = $this->event_model->getAllFormField('application','Masters','Educational Background');
						$this->data['application_education_extra'] = $this->event_model->getAllFormField('application','Extra','Educational Background');
						$this->data['application_form_docs'] = $this->event_model->getAllFormField('application','Documents','');
						
						$this->data['nomination_form_personal'] = $this->event_model->getAllFormField('nomination','Nominee Personal','Nominee');
						$this->data['nomination_form_contact'] = $this->event_model->getAllFormField('nomination','Nominee Contact','Nominee');
						$this->data['nomination_form_extra'] = $this->event_model->getAllFormField('nomination','Nominee Extra','Nominee');
						$this->data['nomination_form_nominant'] = $this->event_model->getAllFormField('nomination','Nominating Personal','Nominating Party');
						$this->data['nomination_form_nominant_extra'] = $this->event_model->getAllFormField('nomination','Nominating Extra','Nominating Party');
						$this->data['nomination_form_disclosure'] = $this->event_model->getAllFormField('nomination','','Disclosure Notice');
						$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
						$this->form_validation->unset_field_data();
						$this->load->view('admin/manage_event/create_event',$this->data);
						
					}
					else
					{
						$val = $this->event_model->editEventNominationForm($this->data['post_value']);
						if($val > 0)
						{
							if(isset($this->data['post_value']['form_type']) && $this->data['post_value']['form_type']!=''){
								$this->session->set_userdata('event_success', $this->data['post_value']['form_type'].' form created successfully.');
							}
							else {
								$this->session->set_userdata('event_success', 'Form created successfully.');
							}
							header('Location: '.BASE_URL.'/'.$this->admin.'/create_event');
							redirect(BASE_URL.'/'.$this->admin.'/create_event');
							exit();
						}
						else
						{
							$this->data['error']='Problem in creating event nomination form';
							$this->data['application_form_personal'] = $this->event_model->getAllFormField('application','Personal','Applicant Particulars');
							$this->data['application_form_contact'] = $this->event_model->getAllFormField('application','Contact','Applicant Particulars');
							$this->data['application_form_extra'] = $this->event_model->getAllFormField('application','Extra','Applicant Particulars');
							$this->data['application_education_pg'] = $this->event_model->getAllFormField('application','Postgraduate','Educational Background');
							$this->data['application_education_phd'] = $this->event_model->getAllFormField('application','PhD','Educational Background');
							$this->data['application_education_master'] = $this->event_model->getAllFormField('application','Masters','Educational Background');
							$this->data['application_education_extra'] = $this->event_model->getAllFormField('application','Extra','Educational Background');
							$this->data['application_form_docs'] = $this->event_model->getAllFormField('application','Documents','');
							
							$this->data['nomination_form_personal'] = $this->event_model->getAllFormField('nomination','Nominee Personal','Nominee');
							$this->data['nomination_form_contact'] = $this->event_model->getAllFormField('nomination','Nominee Contact','Nominee');
							$this->data['nomination_form_extra'] = $this->event_model->getAllFormField('nomination','Nominee Extra','Nominee');
							$this->data['nomination_form_nominant'] = $this->event_model->getAllFormField('nomination','Nominating Personal','Nominating Party');
							$this->data['nomination_form_nominant_extra'] = $this->event_model->getAllFormField('nomination','Nominating Extra','Nominating Party');
							$this->data['nomination_form_disclosure'] = $this->event_model->getAllFormField('nomination','','Disclosure Notice');
							$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
							$this->form_validation->unset_field_data();
							$this->load->view('admin/manage_event/create_event',$this->data);
						}
					}
				}
				else
				{
					$this->data['post_value'] = $this->input->post();	
					$this->data['error'] = validation_errors();
					$this->data['application_form_personal'] = $this->event_model->getAllFormField('application','Personal','Applicant Particulars');
					$this->data['application_form_contact'] = $this->event_model->getAllFormField('application','Contact','Applicant Particulars');
					$this->data['application_form_extra'] = $this->event_model->getAllFormField('application','Extra','Applicant Particulars');
					$this->data['application_education_pg'] = $this->event_model->getAllFormField('application','Postgraduate','Educational Background');
					$this->data['application_education_phd'] = $this->event_model->getAllFormField('application','PhD','Educational Background');
					$this->data['application_education_master'] = $this->event_model->getAllFormField('application','Masters','Educational Background');
					$this->data['application_education_extra'] = $this->event_model->getAllFormField('application','Extra','Educational Background');
					$this->data['application_form_docs'] = $this->event_model->getAllFormField('application','Documents','');
					
					$this->data['nomination_form_personal'] = $this->event_model->getAllFormField('nomination','Nominee Personal','Nominee');
					$this->data['nomination_form_contact'] = $this->event_model->getAllFormField('nomination','Nominee Contact','Nominee');
					$this->data['nomination_form_extra'] = $this->event_model->getAllFormField('nomination','Nominee Extra','Nominee');
					$this->data['nomination_form_nominant'] = $this->event_model->getAllFormField('nomination','Nominating Personal','Nominating Party');
					$this->data['nomination_form_nominant_extra'] = $this->event_model->getAllFormField('nomination','Nominating Extra','Nominating Party');
					$this->data['nomination_form_disclosure'] = $this->event_model->getAllFormField('nomination','','Disclosure Notice');
					$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
					$this->form_validation->unset_field_data();
					$this->load->view('admin/manage_event/create_event',$this->data);
				}
			}
			else
			{
				$this->data['application_form_personal'] = $this->event_model->getAllFormField('application','Personal','Applicant Particulars');
				$this->data['application_form_contact'] = $this->event_model->getAllFormField('application','Contact','Applicant Particulars');
				$this->data['application_form_extra'] = $this->event_model->getAllFormField('application','Extra','Applicant Particulars');
				$this->data['application_education_pg'] = $this->event_model->getAllFormField('application','Postgraduate','Educational Background');
				$this->data['application_education_phd'] = $this->event_model->getAllFormField('application','PhD','Educational Background');
				$this->data['application_education_master'] = $this->event_model->getAllFormField('application','Masters','Educational Background');
				$this->data['application_education_extra'] = $this->event_model->getAllFormField('application','Extra','Educational Background');
				$this->data['application_form_docs'] = $this->event_model->getAllFormField('application','Documents','');
				
				$this->data['nomination_form_personal'] = $this->event_model->getAllFormField('nomination','Nominee Personal','Nominee');
				$this->data['nomination_form_contact'] = $this->event_model->getAllFormField('nomination','Nominee Contact','Nominee');
				$this->data['nomination_form_extra'] = $this->event_model->getAllFormField('nomination','Nominee Extra','Nominee');
				$this->data['nomination_form_nominant'] = $this->event_model->getAllFormField('nomination','Nominating Personal','Nominating Party');
				$this->data['nomination_form_nominant_extra'] = $this->event_model->getAllFormField('nomination','Nominating Extra','Nominating Party');
				$this->data['nomination_form_disclosure'] = $this->event_model->getAllFormField('nomination','','Disclosure Notice');
				$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
				$this->load->view('admin/manage_event/create_event',$this->data);	
			}
		}
		else{
			$this->session->sess_destroy();
			header('Location: '.BASE_URL.'/login');
			redirect(BASE_URL.'/login');
			exit();
		}
	}
	
	public function manageEvent($value='')
	{
		if($this->session->userdata('admin_id') && $this->session->userdata('admin_id') != '' && $this->session->userdata('logedin'))
		{
			$search_data = 'All';
			
			if(!in_array($value, $this->allowed))
			{
				header('Location: '.BASE_URL.'/'.$this->admin.'/dashboard');
				redirect(BASE_URL.'/'.$this->admin.'/dashboard');
				exit();
			}
			
			if($this->input->post('event_search_name'))
			{
				// Set validation rules.
				$this->form_validation->set_rules('event_search_name', 'Event Search Name','trim|required|xss_clean');
				// Run the validation.
				if ($this->form_validation->run())
				{
					$this->data['post_value'] = $this->input->post();
					$search_data = $this->data['post_value']['event_search_name'];
					$this->data['search_tag'] = $search_data;
					$this->data['search_value'] = $this->event_model->getEventByName($search_data, '0', '10');
					$this->data['search_count'] = $this->event_model->getEventByName($search_data, '', '');
					$this->load->view('admin/manage_event/manage_event',$this->data);
				}
				else
				{
					$this->data['post_value'] = $this->input->post();
					$this->data['error'] = validation_errors();
					$this->load->view('admin/manage_event/manage_event',$this->data);
				}
			}
			else if($this->input->get('page'))
			{
				$this->data['search_count'] = $this->event_model->getEventByName($search_data, '', '');
				$page = $this->input->get('page');
				if($page <= 1)
				{
					$start = 0;
				}else{
					$start = ($page-1)*10;
				}
				$this->data['search_value'] = $this->event_model->getEventByName($search_data, $start, '10');
				$this->load->view('admin/manage_event/manage_event',$this->data);
			}
			else
			{
				$this->data['search_count'] = $this->event_model->getEventByName($search_data, '', '');
				$this->data['search_value'] = $this->event_model->getEventByName($search_data, '0', '10');
				$this->load->view('admin/manage_event/manage_event',$this->data);	
			}
		}
		else{
			$this->session->sess_destroy();
			header('Location: '.BASE_URL.'/login');
			redirect(BASE_URL.'/login');
			exit();
		}
	}

	public function modifyEvent($value='')
	{
		if($this->session->userdata('admin_id') && $this->session->userdata('admin_id') != '' && $this->session->userdata('logedin'))
		{
			$search_data = 'All';
			
			if(!in_array($value, $this->allowed))
			{
				header('Location: '.BASE_URL.'/'.$this->admin.'/dashboard');
				redirect(BASE_URL.'/'.$this->admin.'/dashboard');
				exit();
			}
			
			if($this->input->get('id') && $this->input->get('id') != '' && preg_match('/^[0-9]+$/',$this->input->get('id')))
			{
				if($this->input->get('type') && $this->input->get('type') != '' && preg_match("/^[A-Za-z]+$/",$this->input->get('type')))
				{
					$this->data['get_value'] = $this->input->get();
					if($this->input->get('type') == 'delete')
					{
						$this->event_model->updateEventStatus($this->input->get('id'), 'Deleted');
						$this->session->set_userdata('event_success', 'Event deleted successfully');
						header('Location: '.BASE_URL.'/'.$this->admin.'/manage_event');
						redirect(BASE_URL.'/'.$this->admin.'/manage_event');
						exit();
					}
					if($this->input->get('type') == 'Active' || $this->input->get('type') == 'Inactive')
					{
						if($this->input->get('type') == 'Active') $stat = 'Inactive';
						if($this->input->get('type') == 'Inactive') $stat = 'Active';
						$this->event_model->updateEventStatus($this->input->get('id'), $stat);
						$this->session->set_userdata('event_success', 'Event is now '.$stat);
						header('Location: '.BASE_URL.'/'.$this->admin.'/manage_event');
						redirect(BASE_URL.'/'.$this->admin.'/manage_event');
						exit();
					}
					if($this->input->get('type') == 'edit')
					{
						$this->session->set_userdata('edit_event', $this->input->get('id'));
						header('Location: '.BASE_URL.'/'.$this->admin.'/edit_event');
						redirect(BASE_URL.'/'.$this->admin.'/edit_event');
						exit();
					}
				}
				else {
					header('Location: '.BASE_URL.'/'.$this->admin.'/manage_event');
					redirect(BASE_URL.'/'.$this->admin.'/manage_event');
					exit();
				}
			}
			else
			{
				header('Location: '.BASE_URL.'/'.$this->admin.'/manage_event');
				redirect(BASE_URL.'/'.$this->admin.'/manage_event');
				exit();
			}
		}
		else{
			$this->session->sess_destroy();
			header('Location: '.BASE_URL.'/login');
			redirect(BASE_URL.'/login');
			exit();
		}
	}
	
	public function editEvent($value='')
	{
		if($this->session->userdata('admin_id') && $this->session->userdata('admin_id') != '' && $this->session->userdata('logedin'))
		{
			if(!in_array($value, $this->allowed))
			{
				header('Location: '.BASE_URL.'/'.$this->admin.'/dashboard');
				redirect(BASE_URL.'/'.$this->admin.'/dashboard');
				exit();
			}
			
			if($this->input->post('eventname'))
			{
				// Set validation rules.
				$this->form_validation->set_rules('eventname', 'Event Name','trim|required|xss_clean');
				$this->form_validation->set_rules('description', 'Event Description','trim|required|xss_clean');
				$this->form_validation->set_rules('category', 'Event Category','trim|xss_clean');
				// Run the validation.
				if ($this->form_validation->run())
				{

					$this->data['post_value'] = $this->input->post();
					$val = $this->event_model->updateEvent($this->data['post_value']);
					$this->session->set_userdata('event_success', 'Event updated succefully');
					$this->session->set_userdata('edit_event', '');
					header('Location: '.BASE_URL.'/'.$this->admin.'/manage_event');
					redirect(BASE_URL.'/'.$this->admin.'/manage_event');
					exit();
				}
				else
				{
					$this->data['error'] = validation_errors();
					$this->data['post_value'] = $this->event_model->getEventById($this->session->userdata('edit_event'));
					$this->load->view('admin/manage_event/edit_event',$this->data);
				}
			}
			else if($this->input->post('form_type') && $this->input->post('form_type') == 'Application')
			{
				
				// Set validation rules.
				$this->form_validation->set_rules('choose_event', 'Choose Event','trim|required|xss_clean');
				$this->form_validation->set_rules('activation_status', 'Activation Status','trim|required|xss_clean');
				$this->form_validation->set_rules('form_header', 'Form Header','trim|xss_clean');
				$this->form_validation->set_rules('form_footer', 'Form Footer','trim|xss_clean');
				$this->form_validation->set_rules('thanks_page', 'Thankyou Page','trim|xss_clean');
				$this->form_validation->set_rules('decline_page', 'Decline Page','trim|xss_clean');
				
				$this->form_validation->set_rules('ap_field1', 'First Name','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field3', 'Last Name','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field4', 'Nationality','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field5', 'Country of Residence','trim|required|xss_clean');
				//$this->form_validation->set_rules('ap_field6', 'Gender','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field9', 'Date of Birth','trim|required|xss_clean');
				//$this->form_validation->set_rules('ap_field10', 'Place of Birth','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field11', 'Telephone','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field13', 'Correspondence Address','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field14', 'Postal Code','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field15', 'State/Province','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field16', 'Country','trim|required|xss_clean');
				for($i=19;$i<=38;$i++)
				{
					if($this->input->post('ap_field'.$i.'_text') && $this->input->post('ap_field'.$i.'_text') != '')
					{
						$this->form_validation->set_rules('ap_field'.$i.'_text', $this->input->post('ap_field'.$i.'_text'),'trim');
					}
				}
				for($n=53;$n<=72;$n++)
				{
					if($this->input->post('ap_field'.$n.'_text') && $this->input->post('ap_field'.$n.'_text') != '')
					{
						$this->form_validation->set_rules('ap_field'.$n.'_text', $this->input->post('ap_field'.$n.'_text'),'trim|xss_clean');
					}
				}
				// Run the validation.
				if ($this->form_validation->run())
				{
					$this->data['post_value'] = $this->input->post();
					if($this->event_model->checkEventForm($this->data['post_value']['choose_event']))
					{
						$this->data['error']='Application Form for this event already exists';
						$this->data['application_form_personal'] = $this->event_model->getAllFormField('application','Personal','Applicant Particulars');
						$this->data['application_form_contact'] = $this->event_model->getAllFormField('application','Contact','Applicant Particulars');
						$this->data['application_form_extra'] = $this->event_model->getAllFormField('application','Extra','Applicant Particulars');
						$this->data['application_education_pg'] = $this->event_model->getAllFormField('application','Postgraduate','Educational Background');
						$this->data['application_education_phd'] = $this->event_model->getAllFormField('application','PhD','Educational Background');
						$this->data['application_education_master'] = $this->event_model->getAllFormField('application','Masters','Educational Background');
						$this->data['application_education_extra'] = $this->event_model->getAllFormField('application','Extra','Educational Background');
						$this->data['application_form_docs'] = $this->event_model->getAllFormField('application','Documents','');
						
						$this->data['nomination_form_personal'] = $this->event_model->getAllFormField('nomination','Nominee Personal','Nominee');
						$this->data['nomination_form_contact'] = $this->event_model->getAllFormField('nomination','Nominee Contact','Nominee');
						$this->data['nomination_form_extra'] = $this->event_model->getAllFormField('nomination','Nominee Extra','Nominee');
						$this->data['nomination_form_nominant'] = $this->event_model->getAllFormField('nomination','Nominating Personal','Nominating Party');
						$this->data['nomination_form_nominant_extra'] = $this->event_model->getAllFormField('nomination','Nominating Extra','Nominating Party');
						$this->data['nomination_form_disclosure'] = $this->event_model->getAllFormField('nomination','','Disclosure Notice');
						$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
						$this->load->view('admin/manage_event/edit_event',$this->data);
					}
					else
					{
						$val = $this->event_model->editEventForm($this->data['post_value']);
						if($val > 0)
						{
							if(isset($this->data['post_value']['form_type']) && $this->data['post_value']['form_type']!=''){
								$this->session->set_userdata('event_success', $this->data['post_value']['form_type'].' Form updated successfully.');
							}
							else {
								$this->session->set_userdata('event_success', 'Form updated successfully.');
							}
							//$this->session->set_userdata('form_type', $this->data['post_value']['form_type']);
							header('Location: '.BASE_URL.'/'.$this->admin.'/edit_event');
							redirect(BASE_URL.'/'.$this->admin.'/edit_event');
							exit();
						}
						else
						{
							$this->data['error']='Problem in creating Event Form';
							$this->data['application_form_personal'] = $this->event_model->getAllFormField('application','Personal','Applicant Particulars');
							$this->data['application_form_contact'] = $this->event_model->getAllFormField('application','Contact','Applicant Particulars');
							$this->data['application_form_extra'] = $this->event_model->getAllFormField('application','Extra','Applicant Particulars');
							$this->data['application_education_pg'] = $this->event_model->getAllFormField('application','Postgraduate','Educational Background');
							$this->data['application_education_phd'] = $this->event_model->getAllFormField('application','PhD','Educational Background');
							$this->data['application_education_master'] = $this->event_model->getAllFormField('application','Masters','Educational Background');
							$this->data['application_education_extra'] = $this->event_model->getAllFormField('application','Extra','Educational Background');
							$this->data['application_form_docs'] = $this->event_model->getAllFormField('application','Documents','');
							
							$this->data['nomination_form_personal'] = $this->event_model->getAllFormField('nomination','Nominee Personal','Nominee');
							$this->data['nomination_form_contact'] = $this->event_model->getAllFormField('nomination','Nominee Contact','Nominee');
							$this->data['nomination_form_extra'] = $this->event_model->getAllFormField('nomination','Nominee Extra','Nominee');
							$this->data['nomination_form_nominant'] = $this->event_model->getAllFormField('nomination','Nominating Personal','Nominating Party');
							$this->data['nomination_form_nominant_extra'] = $this->event_model->getAllFormField('nomination','Nominating Extra','Nominating Party');
							$this->data['nomination_form_disclosure'] = $this->event_model->getAllFormField('nomination','','Disclosure Notice');
							$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
							$this->load->view('admin/manage_event/create_event',$this->data);
						}
					}
				}
			}
			else if($this->input->post('form_type') && $this->input->post('form_type') == 'Nomination')
			{
				// Set validation rules.
				$this->form_validation->set_rules('choose_event1', 'Choose Event','trim|required|xss_clean');
				$this->form_validation->set_rules('activation_status1', 'Activation Status','trim|required|xss_clean');
				$this->form_validation->set_rules('form_header1', 'Form Header','trim|xss_clean');
				$this->form_validation->set_rules('form_footer1', 'Form Footer','trim|xss_clean');
				$this->form_validation->set_rules('thanks_page1', 'Thankyou Page','trim|xss_clean');
				$this->form_validation->set_rules('decline_page1', 'Decline Page','trim|xss_clean');
				
				$this->form_validation->set_rules('nom_field1', 'Nominee\'s First Name','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field3', 'Nominee\'s Last Name','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field4', 'Nationality','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field5', 'Country of Residence','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field11', 'Telephone','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field13', 'Correspondence Address','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field14', 'Postal Code','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field15', 'State/Province','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field16', 'Country','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field16', 'Email','trim|required|xss_clean');
				for($i=19;$i<=24;$i++)
				{
					//var_dump('test'); die();
					if($this->input->post('nom_field'.$i.'_text') && $this->input->post('nom_field'.$i.'_text') != '')
					{
						$this->form_validation->set_rules('nom_field'.$i.'_text', $this->input->post('nom_field'.$i.'_text'),'trim|xss_clean');
					}
				}
				$this->form_validation->set_rules('nom_field25', 'Nominator\'s First Name','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field27', 'Nominator\'s Last Name','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field28', 'Nominator\'s Position','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field29', 'Nominator\'s Institution Affiliation','trim|required|xss_clean');
				//$this->form_validation->set_rules('nom_field32', 'Nominator\'s Email','trim|required|xss_clean');
				for($i=34;$i<=39;$i++)
				{
					if($this->input->post('nom_field'.$i.'_text') && $this->input->post('nom_field'.$i.'_text') != '')
					{
						$this->form_validation->set_rules('nom_field'.$i.'_text', $this->input->post('nom_field'.$i.'_text'),'trim|xss_clean');
					}
				}
				// Run the validation.
				if ($this->form_validation->run())
				{
					$this->data['post_value'] = $this->input->post();
					if($this->event_model->checkEventNominationForm($this->data['post_value']['choose_event1']))
					{
						$this->data['error']='Nomination Form for this event already exists';
						$this->data['application_form_personal'] = $this->event_model->getAllFormField('application','Personal','Applicant Particulars');
						$this->data['application_form_contact'] = $this->event_model->getAllFormField('application','Contact','Applicant Particulars');
						$this->data['application_form_extra'] = $this->event_model->getAllFormField('application','Extra','Applicant Particulars');
						$this->data['application_education_pg'] = $this->event_model->getAllFormField('application','Postgraduate','Educational Background');
						$this->data['application_education_phd'] = $this->event_model->getAllFormField('application','PhD','Educational Background');
						$this->data['application_education_master'] = $this->event_model->getAllFormField('application','Masters','Educational Background');
						$this->data['application_education_extra'] = $this->event_model->getAllFormField('application','Extra','Educational Background');
						$this->data['application_form_docs'] = $this->event_model->getAllFormField('application','Documents','');
						
						$this->data['nomination_form_personal'] = $this->event_model->getAllFormField('nomination','Nominee Personal','Nominee');
						$this->data['nomination_form_contact'] = $this->event_model->getAllFormField('nomination','Nominee Contact','Nominee');
						$this->data['nomination_form_extra'] = $this->event_model->getAllFormField('nomination','Nominee Extra','Nominee');
						$this->data['nomination_form_nominant'] = $this->event_model->getAllFormField('nomination','Nominating Personal','Nominating Party');
						$this->data['nomination_form_nominant_extra'] = $this->event_model->getAllFormField('nomination','Nominating Extra','Nominating Party');
						$this->data['nomination_form_disclosure'] = $this->event_model->getAllFormField('nomination','','Disclosure Notice');
						$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
						$this->load->view('admin/manage_event/create_event',$this->data);
						
					}
					else
					{
						$val = $this->event_model->editEventNominationForm($this->data['post_value']);
						if($val > 0)
						{
							if(isset($this->data['post_value']['form_type']) && $this->data['post_value']['form_type']!=''){
								$this->session->set_userdata('event_success', $this->data['post_value']['form_type'].' Form Edit successfully.');
							}
							else {
								$this->session->set_userdata('event_success', 'Form Edit successfully.');
							}
							//$this->session->set_userdata('form_type', $this->data['post_value']['form_type']);
							header('Location: '.BASE_URL.'/'.$this->admin.'/edit_event');
							redirect(BASE_URL.'/'.$this->admin.'/edit_event');
							exit();
						}
						else
						{
							$this->data['error']='Problem in creating Event Form';
							$this->data['application_form_personal'] = $this->event_model->getAllFormField('application','Personal','Applicant Particulars');
							$this->data['application_form_contact'] = $this->event_model->getAllFormField('application','Contact','Applicant Particulars');
							$this->data['application_form_extra'] = $this->event_model->getAllFormField('application','Extra','Applicant Particulars');
							$this->data['application_education_pg'] = $this->event_model->getAllFormField('application','Postgraduate','Educational Background');
							$this->data['application_education_phd'] = $this->event_model->getAllFormField('application','PhD','Educational Background');
							$this->data['application_education_master'] = $this->event_model->getAllFormField('application','Masters','Educational Background');
							$this->data['application_education_extra'] = $this->event_model->getAllFormField('application','Extra','Educational Background');
							$this->data['application_form_docs'] = $this->event_model->getAllFormField('application','Documents','');
							
							$this->data['nomination_form_personal'] = $this->event_model->getAllFormField('nomination','Nominee Personal','Nominee');
							$this->data['nomination_form_contact'] = $this->event_model->getAllFormField('nomination','Nominee Contact','Nominee');
							$this->data['nomination_form_extra'] = $this->event_model->getAllFormField('nomination','Nominee Extra','Nominee');
							$this->data['nomination_form_nominant'] = $this->event_model->getAllFormField('nomination','Nominating Personal','Nominating Party');
							$this->data['nomination_form_nominant_extra'] = $this->event_model->getAllFormField('nomination','Nominating Extra','Nominating Party');
							$this->data['nomination_form_disclosure'] = $this->event_model->getAllFormField('nomination','','Disclosure Notice');
							$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
							$this->load->view('admin/manage_event/edit_event',$this->data);
						}
					}
				}
				else
				{
					$this->data['post_value'] = $this->input->post();	
					$this->data['error'] = validation_errors();
					$this->data['application_form_personal'] = $this->event_model->getAllFormField('application','Personal','Applicant Particulars');
					$this->data['application_form_contact'] = $this->event_model->getAllFormField('application','Contact','Applicant Particulars');
					$this->data['application_form_extra'] = $this->event_model->getAllFormField('application','Extra','Applicant Particulars');
					$this->data['application_education_pg'] = $this->event_model->getAllFormField('application','Postgraduate','Educational Background');
					$this->data['application_education_phd'] = $this->event_model->getAllFormField('application','PhD','Educational Background');
					$this->data['application_education_master'] = $this->event_model->getAllFormField('application','Masters','Educational Background');
					$this->data['application_education_extra'] = $this->event_model->getAllFormField('application','Extra','Educational Background');
					$this->data['application_form_docs'] = $this->event_model->getAllFormField('application','Documents','');
					
					$this->data['nomination_form_personal'] = $this->event_model->getAllFormField('nomination','Nominee Personal','Nominee');
					$this->data['nomination_form_contact'] = $this->event_model->getAllFormField('nomination','Nominee Contact','Nominee');
					$this->data['nomination_form_extra'] = $this->event_model->getAllFormField('nomination','Nominee Extra','Nominee');
					$this->data['nomination_form_nominant'] = $this->event_model->getAllFormField('nomination','Nominating Personal','Nominating Party');
					$this->data['nomination_form_nominant_extra'] = $this->event_model->getAllFormField('nomination','Nominating Extra','Nominating Party');
					$this->data['nomination_form_disclosure'] = $this->event_model->getAllFormField('nomination','','Disclosure Notice');
					$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
					$this->load->view('admin/manage_event/edit_event',$this->data);
				}
			}
			
			else if($this->session->userdata('edit_event'))
			{
				$this->data['application_form_personal'] = $this->event_model->getAllFormField('application','Personal','Applicant Particulars');
				$this->data['application_form_contact'] = $this->event_model->getAllFormField('application','Contact','Applicant Particulars');
				$this->data['application_form_extra'] = $this->event_model->getAllFormField('application','Extra','Applicant Particulars');
				$this->data['application_education_pg'] = $this->event_model->getAllFormField('application','Postgraduate','Educational Background');
				$this->data['application_education_phd'] = $this->event_model->getAllFormField('application','PhD','Educational Background');
				$this->data['application_education_master'] = $this->event_model->getAllFormField('application','Masters','Educational Background');
				$this->data['application_education_extra'] = $this->event_model->getAllFormField('application','Extra','Educational Background');
				$this->data['application_form_docs'] = $this->event_model->getAllFormField('application','Documents','');
				
				$this->data['nomination_form_personal'] = $this->event_model->getAllFormField('nomination','Nominee Personal','Nominee');
				$this->data['nomination_form_contact'] = $this->event_model->getAllFormField('nomination','Nominee Contact','Nominee');
				$this->data['nomination_form_extra'] = $this->event_model->getAllFormField('nomination','Nominee Extra','Nominee');
				$this->data['nomination_form_nominant'] = $this->event_model->getAllFormField('nomination','Nominating Personal','Nominating Party');
				$this->data['nomination_form_nominant_extra'] = $this->event_model->getAllFormField('nomination','Nominating Extra','Nominating Party');
				$this->data['nomination_form_disclosure'] = $this->event_model->getAllFormField('nomination','','Disclosure Notice');
				$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');	
				$this->data['personal_field_data'] = $this->event_model->get_field_data('Applicant Particulars');
				$this->data['educational_field_data'] = $this->event_model->get_field_data('Educational Background');
				$this->data['document_field_data'] = $this->event_model->get_field_data('Document');
				$this->data['post_value'] = $this->event_model->getEventById($this->session->userdata('edit_event'));
				$this->data['header_data'] = $this->event_model->get_header_data('event_application_event_id','scopus_event_application_form_headers');
				$this->data['header_data_nomination'] = $this->event_model->get_header_data('event_nomination_event_id','scopus_event_nomination_form_headers');
				$this->data['Nominee_field_data'] = $this->event_model->get_field_data_nomination('Nominee');
				$this->data['Nominating_field_data'] = $this->event_model->get_field_data_nomination('Nominating Party');
				$this->data['Disclosure_field_data'] = $this->event_model->get_field_data_nomination('Disclosure Notice');
				$this->load->view('admin/manage_event/edit_event',$this->data);
			}	
			
			else
			{
				header('Location: '.BASE_URL.'/'.$this->admin.'/manage_event');
				redirect(BASE_URL.'/'.$this->admin.'/manage_event');
				exit();
			}	
		}
			
		
		else{
			$this->session->sess_destroy();
			header('Location: '.BASE_URL.'/login');
			redirect(BASE_URL.'/login');
			exit();
		}
	}

	public function createEventForm($value='')
	{
		if($this->session->userdata('admin_id') && $this->session->userdata('admin_id') != '' && $this->session->userdata('logedin'))
		{
			if(!in_array($value, $this->allowed))
			{
				header('Location: '.BASE_URL.'/'.$this->admin.'/dashboard');
				redirect(BASE_URL.'/'.$this->admin.'/dashboard');
				exit();
			}
			
			if($this->input->post('form_type') && $this->input->post('form_type') == 'Application')
			{
				// Set validation rules.
				$this->form_validation->set_rules('choose_event', 'Choose Event','trim|required|xss_clean');
				$this->form_validation->set_rules('activation_status', 'Activation Status','trim|required|xss_clean');
				$this->form_validation->set_rules('form_header', 'Form Header','trim|xss_clean');
				$this->form_validation->set_rules('form_footer', 'Form Footer','trim|xss_clean');
				$this->form_validation->set_rules('thanks_page', 'Thankyou Page','trim|xss_clean');
				$this->form_validation->set_rules('decline_page', 'Decline Page','trim|xss_clean');
				
				$this->form_validation->set_rules('ap_field1', 'First Name','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field3', 'Last Name','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field4', 'Nationality','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field5', 'Country of Residence','trim|required|xss_clean');
				//$this->form_validation->set_rules('ap_field6', 'Gender','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field9', 'Date of Birth','trim|required|xss_clean');
				//$this->form_validation->set_rules('ap_field10', 'Place of Birth','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field11', 'Telephone','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field13', 'Correspondence Address','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field14', 'Postal Code','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field15', 'State/Province','trim|required|xss_clean');
				$this->form_validation->set_rules('ap_field16', 'Country','trim|required|xss_clean');
				for($i=19;$i<=38;$i++)
				{
					if($this->input->post('ap_field'.$i.'_text') && $this->input->post('ap_field'.$i.'_text') != '')
					{
						$this->form_validation->set_rules('ap_field'.$i.'_text', $this->input->post('ap_field'.$i.'_text'),'trim');
					}
				}
				for($n=53;$n<=72;$n++)
				{
					if($this->input->post('ap_field'.$n.'_text') && $this->input->post('ap_field'.$n.'_text') != '')
					{
						$this->form_validation->set_rules('ap_field'.$n.'_text', $this->input->post('ap_field'.$n.'_text'),'trim|xss_clean');
					}
				}
				// Run the validation.
				if ($this->form_validation->run())
				{
					$this->data['post_value'] = $this->input->post();
					if($this->event_model->checkEventForm($this->data['post_value']['choose_event']))
					{
						$this->data['error']='Application Form for this event already exists';
						$this->data['application_form_personal'] = $this->event_model->getAllFormField('application','Personal','Applicant Particulars');
						$this->data['application_form_contact'] = $this->event_model->getAllFormField('application','Contact','Applicant Particulars');
						$this->data['application_form_extra'] = $this->event_model->getAllFormField('application','Extra','Applicant Particulars');
						$this->data['application_education_pg'] = $this->event_model->getAllFormField('application','Postgraduate','Educational Background');
						$this->data['application_education_phd'] = $this->event_model->getAllFormField('application','PhD','Educational Background');
						$this->data['application_education_master'] = $this->event_model->getAllFormField('application','Masters','Educational Background');
						$this->data['application_education_extra'] = $this->event_model->getAllFormField('application','Extra','Educational Background');
						$this->data['application_form_docs'] = $this->event_model->getAllFormField('application','Documents','');
						
						$this->data['nomination_form_personal'] = $this->event_model->getAllFormField('nomination','Nominee Personal','Nominee');
						$this->data['nomination_form_contact'] = $this->event_model->getAllFormField('nomination','Nominee Contact','Nominee');
						$this->data['nomination_form_extra'] = $this->event_model->getAllFormField('nomination','Nominee Extra','Nominee');
						$this->data['nomination_form_nominant'] = $this->event_model->getAllFormField('nomination','Nominating Personal','Nominating Party');
						$this->data['nomination_form_nominant_extra'] = $this->event_model->getAllFormField('nomination','Nominating Extra','Nominating Party');
						$this->data['nomination_form_disclosure'] = $this->event_model->getAllFormField('nomination','','Disclosure Notice');
						$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
						$this->load->view('admin/manage_event/create_event',$this->data);
						
					}
					else
					{
						$val = $this->event_model->addEventForm($this->data['post_value']);
						if($val > 0)
						{
							if(isset($this->data['post_value']['form_type']) && $this->data['post_value']['form_type']!=''){
								$this->session->set_userdata('event_success', $this->data['post_value']['form_type'].' Form added successfully.');
							}
							else {
								$this->session->set_userdata('event_success', 'Form added successfully.');
							}
							//$this->session->set_userdata('form_type', $this->data['post_value']['form_type']);
							header('Location: '.BASE_URL.'/'.$this->admin.'/create_event');
							redirect(BASE_URL.'/'.$this->admin.'/create_event');
							exit();
						}
						else
						{
							$this->data['error']='Problem in creating Event Form';
							$this->data['application_form_personal'] = $this->event_model->getAllFormField('application','Personal','Applicant Particulars');
							$this->data['application_form_contact'] = $this->event_model->getAllFormField('application','Contact','Applicant Particulars');
							$this->data['application_form_extra'] = $this->event_model->getAllFormField('application','Extra','Applicant Particulars');
							$this->data['application_education_pg'] = $this->event_model->getAllFormField('application','Postgraduate','Educational Background');
							$this->data['application_education_phd'] = $this->event_model->getAllFormField('application','PhD','Educational Background');
							$this->data['application_education_master'] = $this->event_model->getAllFormField('application','Masters','Educational Background');
							$this->data['application_education_extra'] = $this->event_model->getAllFormField('application','Extra','Educational Background');
							$this->data['application_form_docs'] = $this->event_model->getAllFormField('application','Documents','');
							
							$this->data['nomination_form_personal'] = $this->event_model->getAllFormField('nomination','Nominee Personal','Nominee');
							$this->data['nomination_form_contact'] = $this->event_model->getAllFormField('nomination','Nominee Contact','Nominee');
							$this->data['nomination_form_extra'] = $this->event_model->getAllFormField('nomination','Nominee Extra','Nominee');
							$this->data['nomination_form_nominant'] = $this->event_model->getAllFormField('nomination','Nominating Personal','Nominating Party');
							$this->data['nomination_form_nominant_extra'] = $this->event_model->getAllFormField('nomination','Nominating Extra','Nominating Party');
							$this->data['nomination_form_disclosure'] = $this->event_model->getAllFormField('nomination','','Disclosure Notice');
							$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
							$this->load->view('admin/manage_event/create_event',$this->data);
						}
					}
				}
				else
				{
					$this->data['post_value'] = $this->input->post();	
					$this->data['error'] = validation_errors();
					$this->data['application_form_personal'] = $this->event_model->getAllFormField('application','Personal','Applicant Particulars');
					$this->data['application_form_contact'] = $this->event_model->getAllFormField('application','Contact','Applicant Particulars');
					$this->data['application_form_extra'] = $this->event_model->getAllFormField('application','Extra','Applicant Particulars');
					$this->data['application_education_pg'] = $this->event_model->getAllFormField('application','Postgraduate','Educational Background');
					$this->data['application_education_phd'] = $this->event_model->getAllFormField('application','PhD','Educational Background');
					$this->data['application_education_master'] = $this->event_model->getAllFormField('application','Masters','Educational Background');
					$this->data['application_education_extra'] = $this->event_model->getAllFormField('application','Extra','Educational Background');
					$this->data['application_form_docs'] = $this->event_model->getAllFormField('application','Documents','');
					
					$this->data['nomination_form_personal'] = $this->event_model->getAllFormField('nomination','Nominee Personal','Nominee');
					$this->data['nomination_form_contact'] = $this->event_model->getAllFormField('nomination','Nominee Contact','Nominee');
					$this->data['nomination_form_extra'] = $this->event_model->getAllFormField('nomination','Nominee Extra','Nominee');
					$this->data['nomination_form_nominant'] = $this->event_model->getAllFormField('nomination','Nominating Personal','Nominating Party');
					$this->data['nomination_form_nominant_extra'] = $this->event_model->getAllFormField('nomination','Nominating Extra','Nominating Party');
					$this->data['nomination_form_disclosure'] = $this->event_model->getAllFormField('nomination','','Disclosure Notice');
					$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
					$this->load->view('admin/manage_event/create_event',$this->data);
				}
			}
			else if($this->input->post('form_type') && $this->input->post('form_type') == 'Nomination')
			{
				// Set validation rules.
				$this->form_validation->set_rules('choose_event1', 'Choose Event','trim|required|xss_clean');
				$this->form_validation->set_rules('activation_status1', 'Activation Status','trim|required|xss_clean');
				$this->form_validation->set_rules('form_header1', 'Form Header','trim|xss_clean');
				$this->form_validation->set_rules('form_footer1', 'Form Footer','trim|xss_clean');
				$this->form_validation->set_rules('thanks_page1', 'Thankyou Page','trim|xss_clean');
				$this->form_validation->set_rules('decline_page1', 'Decline Page','trim|xss_clean');
				
				$this->form_validation->set_rules('nom_field1', 'Nominee\'s First Name','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field3', 'Nominee\'s Last Name','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field4', 'Nationality','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field5', 'Country of Residence','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field11', 'Telephone','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field13', 'Correspondence Address','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field14', 'Postal Code','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field15', 'State/Province','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field16', 'Country','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field16', 'Email','trim|required|xss_clean');
				for($i=19;$i<=24;$i++)
				{
					if($this->input->post('nom_field'.$i.'_text') && $this->input->post('nom_field'.$i.'_text') != '')
					{
						$this->form_validation->set_rules('nom_field'.$i.'_text', $this->input->post('nom_field'.$i.'_text'),'trim|xss_clean');
					}
				}
				$this->form_validation->set_rules('nom_field25', 'Nominator\'s First Name','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field27', 'Nominator\'s Last Name','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field28', 'Nominator\'s Position','trim|required|xss_clean');
				$this->form_validation->set_rules('nom_field29', 'Nominator\'s Institution Affiliation','trim|required|xss_clean');
				//$this->form_validation->set_rules('nom_field32', 'Nominator\'s Email','trim|required|xss_clean');
				for($i=34;$i<=39;$i++)
				{
					if($this->input->post('nom_field'.$i.'_text') && $this->input->post('nom_field'.$i.'_text') != '')
					{
						$this->form_validation->set_rules('nom_field'.$i.'_text', $this->input->post('nom_field'.$i.'_text'),'trim|xss_clean');
					}
				}
				
				// Run the validation.
				if ($this->form_validation->run())
				{
					$this->data['post_value'] = $this->input->post();
					if($this->event_model->checkEventNominationForm($this->data['post_value']['choose_event1']))
					{
						$this->data['error']='Nomination Form for this event already exists';
						$this->data['application_form_personal'] = $this->event_model->getAllFormField('application','Personal','Applicant Particulars');
						$this->data['application_form_contact'] = $this->event_model->getAllFormField('application','Contact','Applicant Particulars');
						$this->data['application_form_extra'] = $this->event_model->getAllFormField('application','Extra','Applicant Particulars');
						$this->data['application_education_pg'] = $this->event_model->getAllFormField('application','Postgraduate','Educational Background');
						$this->data['application_education_phd'] = $this->event_model->getAllFormField('application','PhD','Educational Background');
						$this->data['application_education_master'] = $this->event_model->getAllFormField('application','Masters','Educational Background');
						$this->data['application_education_extra'] = $this->event_model->getAllFormField('application','Extra','Educational Background');
						$this->data['application_form_docs'] = $this->event_model->getAllFormField('application','Documents','');
						
						$this->data['nomination_form_personal'] = $this->event_model->getAllFormField('nomination','Nominee Personal','Nominee');
						$this->data['nomination_form_contact'] = $this->event_model->getAllFormField('nomination','Nominee Contact','Nominee');
						$this->data['nomination_form_extra'] = $this->event_model->getAllFormField('nomination','Nominee Extra','Nominee');
						$this->data['nomination_form_nominant'] = $this->event_model->getAllFormField('nomination','Nominating Personal','Nominating Party');
						$this->data['nomination_form_nominant_extra'] = $this->event_model->getAllFormField('nomination','Nominating Extra','Nominating Party');
						$this->data['nomination_form_disclosure'] = $this->event_model->getAllFormField('nomination','','Disclosure Notice');
						$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
						$this->load->view('admin/manage_event/create_event',$this->data);
						
					}
					else
					{
						$val = $this->event_model->addEventNominationForm($this->data['post_value']);
						if($val > 0)
						{
							if(isset($this->data['post_value']['form_type']) && $this->data['post_value']['form_type']!=''){
								$this->session->set_userdata('event_success', $this->data['post_value']['form_type'].' Form added successfully.');
							}
							else {
								$this->session->set_userdata('event_success', 'Form added successfully.');
							}
							//$this->session->set_userdata('form_type', $this->data['post_value']['form_type']);
							header('Location: '.BASE_URL.'/'.$this->admin.'/create_event');
							redirect(BASE_URL.'/'.$this->admin.'/create_event');
							exit();
						}
						else
						{
							$this->data['error']='Problem in creating Event Form';
							$this->data['application_form_personal'] = $this->event_model->getAllFormField('application','Personal','Applicant Particulars');
							$this->data['application_form_contact'] = $this->event_model->getAllFormField('application','Contact','Applicant Particulars');
							$this->data['application_form_extra'] = $this->event_model->getAllFormField('application','Extra','Applicant Particulars');
							$this->data['application_education_pg'] = $this->event_model->getAllFormField('application','Postgraduate','Educational Background');
							$this->data['application_education_phd'] = $this->event_model->getAllFormField('application','PhD','Educational Background');
							$this->data['application_education_master'] = $this->event_model->getAllFormField('application','Masters','Educational Background');
							$this->data['application_education_extra'] = $this->event_model->getAllFormField('application','Extra','Educational Background');
							$this->data['application_form_docs'] = $this->event_model->getAllFormField('application','Documents','');
							
							$this->data['nomination_form_personal'] = $this->event_model->getAllFormField('nomination','Nominee Personal','Nominee');
							$this->data['nomination_form_contact'] = $this->event_model->getAllFormField('nomination','Nominee Contact','Nominee');
							$this->data['nomination_form_extra'] = $this->event_model->getAllFormField('nomination','Nominee Extra','Nominee');
							$this->data['nomination_form_nominant'] = $this->event_model->getAllFormField('nomination','Nominating Personal','Nominating Party');
							$this->data['nomination_form_nominant_extra'] = $this->event_model->getAllFormField('nomination','Nominating Extra','Nominating Party');
							$this->data['nomination_form_disclosure'] = $this->event_model->getAllFormField('nomination','','Disclosure Notice');
							$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
							$this->load->view('admin/manage_event/create_event',$this->data);
						}
					}
				}
				else
				{
					$this->data['post_value'] = $this->input->post();	
					$this->data['error'] = validation_errors();
					$this->data['application_form_personal'] = $this->event_model->getAllFormField('application','Personal','Applicant Particulars');
					$this->data['application_form_contact'] = $this->event_model->getAllFormField('application','Contact','Applicant Particulars');
					$this->data['application_form_extra'] = $this->event_model->getAllFormField('application','Extra','Applicant Particulars');
					$this->data['application_education_pg'] = $this->event_model->getAllFormField('application','Postgraduate','Educational Background');
					$this->data['application_education_phd'] = $this->event_model->getAllFormField('application','PhD','Educational Background');
					$this->data['application_education_master'] = $this->event_model->getAllFormField('application','Masters','Educational Background');
					$this->data['application_education_extra'] = $this->event_model->getAllFormField('application','Extra','Educational Background');
					$this->data['application_form_docs'] = $this->event_model->getAllFormField('application','Documents','');
					
					$this->data['nomination_form_personal'] = $this->event_model->getAllFormField('nomination','Nominee Personal','Nominee');
					$this->data['nomination_form_contact'] = $this->event_model->getAllFormField('nomination','Nominee Contact','Nominee');
					$this->data['nomination_form_extra'] = $this->event_model->getAllFormField('nomination','Nominee Extra','Nominee');
					$this->data['nomination_form_nominant'] = $this->event_model->getAllFormField('nomination','Nominating Personal','Nominating Party');
					$this->data['nomination_form_nominant_extra'] = $this->event_model->getAllFormField('nomination','Nominating Extra','Nominating Party');
					$this->data['nomination_form_disclosure'] = $this->event_model->getAllFormField('nomination','','Disclosure Notice');
					$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
					$this->load->view('admin/manage_event/create_event',$this->data);
				}
			}
			else
			{
				$this->data['application_form_personal'] = $this->event_model->getAllFormField('application','Personal','Applicant Particulars');
				$this->data['application_form_contact'] = $this->event_model->getAllFormField('application','Contact','Applicant Particulars');
				$this->data['application_form_extra'] = $this->event_model->getAllFormField('application','Extra','Applicant Particulars');
				$this->data['application_education_pg'] = $this->event_model->getAllFormField('application','Postgraduate','Educational Background');
				$this->data['application_education_phd'] = $this->event_model->getAllFormField('application','PhD','Educational Background');
				$this->data['application_education_master'] = $this->event_model->getAllFormField('application','Masters','Educational Background');
				$this->data['application_education_extra'] = $this->event_model->getAllFormField('application','Extra','Educational Background');
				$this->data['application_form_docs'] = $this->event_model->getAllFormField('application','Documents','');
				
				$this->data['nomination_form_personal'] = $this->event_model->getAllFormField('nomination','Nominee Personal','Nominee');
				$this->data['nomination_form_contact'] = $this->event_model->getAllFormField('nomination','Nominee Contact','Nominee');
				$this->data['nomination_form_extra'] = $this->event_model->getAllFormField('nomination','Nominee Extra','Nominee');
				$this->data['nomination_form_nominant'] = $this->event_model->getAllFormField('nomination','Nominating Personal','Nominating Party');
				$this->data['nomination_form_nominant_extra'] = $this->event_model->getAllFormField('nomination','Nominating Extra','Nominating Party');
				$this->data['nomination_form_disclosure'] = $this->event_model->getAllFormField('nomination','','Disclosure Notice');
				$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
				$this->load->view('admin/manage_event/create_event',$this->data);	
			}
		}
		else{
			$this->session->sess_destroy();
			header('Location: '.BASE_URL.'/login');
			redirect(BASE_URL.'/login');
			exit();
		}
	}

	public function createAward($value='')
	{	

		if($this->session->userdata('admin_id') && $this->session->userdata('admin_id') != '' && $this->session->userdata('logedin'))
		{
			if(!in_array($value, $this->allowed))
			{
				header('Location: '.BASE_URL.'/'.$this->admin.'/dashboard');
				redirect(BASE_URL.'/'.$this->admin.'/dashboard');
				exit();
			}
			
			if($this->input->post('selectevent'))
			{
				// Set validation rules.
				$this->form_validation->set_rules('selectevent', 'Choose Event','trim|required|xss_clean');
				$this->form_validation->set_rules('awardname', 'Award Name','trim|required|xss_clean');
				$this->form_validation->set_rules('description2', 'Award Description','trim|xss_clean');
				$this->form_validation->set_rules('admin_select', 'Admin Incharge','trim|xss_clean|required');
				$this->form_validation->set_rules('cp_select', 'Chief PanelistPage','trim|xss_clean|required');
				$this->form_validation->set_rules('status_select', 'Award Status','trim|xss_clean');
				$this->form_validation->set_rules('refree_select', 'Award Refree','trim|xss_clean');
				
				if ($this->form_validation->run())
				{
					if(!$this->event_model->checkAwardByName($this->input->post('awardname'),  '', ''))
					{
						$this->data['post_value'] = $this->input->post();
						$this->data['post_value']['file'] = $_FILES;
						$f_id = $this->event_model->addAward($this->data['post_value']);
						if($f_id)
						{
							$this->session->set_userdata('award_id', $f_id);
							$this->session->set_userdata('award_page', 'create');
							$this->session->set_userdata('award_success', ' Award added successfully. Add Criteria now.');
							header('Location: '.BASE_URL.'/'.$this->admin.'/create_award');
							redirect(BASE_URL.'/'.$this->admin.'/create_award');
							exit();
						}
						else{
							$this->session->set_userdata('award_page', 'create');
							$this->session->set_userdata('award_success', 'Problem occured while adding Award.');
							header('Location: '.BASE_URL.'/'.$this->admin.'/create_award');
							redirect(BASE_URL.'/'.$this->admin.'/create_award');
							exit();
						}
					}
					else{
							$this->session->set_userdata('award_page', 'create');
							$this->session->set_userdata('award_success', 'Award with same name already exists.');
							header('Location: '.BASE_URL.'/'.$this->admin.'/create_award');
							redirect(BASE_URL.'/'.$this->admin.'/create_award');
							exit();
					}
				}
				else
				{
					$this->data['post_value'] = $this->input->post();
					$this->data['error'] = validation_errors();
					
					$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
					$this->data['admin_data'] = $this->admin_model->fetch_admin();
					$this->data['panelist_data'] = $this->admin_model->getPanelistByName('All', '', '');
					
					$this->session->set_userdata('award_page', 'create');
					$this->load->view('admin/manage_event/create_award',$this->data);
				}
			}
			else if($this->input->post('create_type') && $this->input->post('create_type') == 'criteria')
			{
				$this->data['post_val'] = $this->input->post();
				$keys = array_keys($this->data['post_val']);
				for($i=0;$i<=count($keys)-1;$i++)
				{
					if(stristr($keys[$i], 'criteria_label'))
					{
						$this->form_validation->set_rules($this->data['post_val'][$keys[$i]], $this->data['post_val'][$keys[$i]],'trim|regex_match[/^[A-Za-z0-9\.\-_&)( ]+$/]|xss_clean');
					}
					if(stristr($keys[$i], 'sub_criteria_l'))
					{
						foreach($this->data['post_val'][$keys[$i]] as $temp)
						{
							$this->form_validation->set_rules($temp, $temp,'trim|regex_match[/^[A-Za-z0-9\.\-_&)( ]+$/]|xss_clean');
						}
					}
					if(stristr($keys[$i], 'criteria_value'))
					{
						$this->form_validation->set_rules($this->data['post_val'][$keys[$i]], $this->data['post_val'][$keys[$i]],'trim|regex_match[/^[0-9.]+$/]|xss_clean|integer');
					}
					if(stristr($keys[$i], 'sub_criteria_v'))
					{
						foreach($this->data['post_val'][$keys[$i]] as $temp)
						{
							$this->form_validation->set_rules($temp, $temp,'trim|regex_match[/^[A-Za-z0-9\.\-_&)( ]+$/]|xss_clean');
						}
					}
				}
				$this->form_validation->set_rules('scoring2', 'Scoring Guideline','trim|xss_clean');
				
				if ($this->form_validation->run())
				{
					if(!$this->event_model->checkAwardCriteria($this->input->post('select_award_id')))
					{
						$f_id = $this->event_model->addAwardCriteria($this->data['post_val']);
						if($f_id)
						{
							$this->session->set_userdata('award_page', 'criteria');
							$this->session->set_userdata('award_success', ' Award Criteria added successfully. Add Panelists now.');
							header('Location: '.BASE_URL.'/'.$this->admin.'/create_award');
							redirect(BASE_URL.'/'.$this->admin.'/create_award');
							exit();
						}
						else{
							$this->session->set_userdata('award_page', 'criteria');
							$this->session->set_userdata('award_success', 'Problem occured while adding Award Criteria.');
							header('Location: '.BASE_URL.'/'.$this->admin.'/create_award');
							redirect(BASE_URL.'/'.$this->admin.'/create_award');
							exit();
						}
					}
					else{
							$this->session->set_userdata('award_page', 'criteria');
							$this->session->set_userdata('award_success', 'Award Criterias already exists. Please update.');
							header('Location: '.BASE_URL.'/'.$this->admin.'/create_award');
							redirect(BASE_URL.'/'.$this->admin.'/create_award');
							exit();
					}
				}
				else
				{
					$this->data['post_value'] = $this->input->post();	
					$this->data['error'] = validation_errors();
					
					$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
					$this->data['admin_data'] = $this->admin_model->fetch_admin();
					$this->data['panelist_data'] = $this->admin_model->getPanelistByName('All', '', '');
					$this->data['award_panelist_data'] = $this->admin_model->getPanelistByAward($this->session->userdata('award_id'));
					$this->data['award_panelist_chief'] = $this->admin_model->getPanelistByAward($this->session->userdata('award_id'), 'chief');
					if(isset($this->data['award_panelist_data']) && !empty($this->data['award_panelist_data']))
					{
						foreach($this->data['award_panelist_data'] as $temp)
						{
							$this->data['award_panelist_ids'][] = $temp['admin_id'];
						}
					}
					$this->data['criteria_data'] = $this->event_model->getCriteriaById($this->session->userdata('edit_award'));
					$this->session->set_userdata('award_page', 'criteria');
					$this->load->view('admin/manage_event/create_award',$this->data);
				}
			}
			else if($this->input->post('create_type') && $this->input->post('create_type') == 'panelist')
			{
				$this->data['post_value'] = $this->input->post();
				$this->event_model->addAwardPanelist($this->data['post_value']);
				
				$this->data['all_awards']  = $this->event_model->getAllAwards();
				$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
				$this->data['admin_data'] = $this->admin_model->fetch_admin();
				$this->data['panelist_data'] = $this->admin_model->getPanelistByName('All', '', '');
				$this->data['award_panelist_data'] = $this->admin_model->getPanelistByAward($this->session->userdata('award_id'));
				$this->data['award_panelist_chief'] = $this->admin_model->getPanelistByAward($this->session->userdata('award_id'), 'chief');
				if(isset($this->data['award_panelist_data']) && !empty($this->data['award_panelist_data']))
				{
					foreach($this->data['award_panelist_data'] as $temp)
					{
						$this->data['award_panelist_ids'][] = $temp['admin_id'];
					}
				}
				$this->data['criteria_data'] = $this->event_model->getCriteriaById($this->session->userdata('award_id'));
				$this->session->set_userdata('award_page', 'panelist');
				$this->session->set_userdata('award_success', ' Award panelist updated successfully');

				$this->load->view('admin/manage_event/create_award',$this->data);
			}
			else{
				$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
				$this->data['admin_data'] = $this->admin_model->fetch_admin();
				$this->data['panelist_data'] = $this->admin_model->getPanelistByName('All', '', '');
				$this->data['award_panelist_data'] = $this->admin_model->getPanelistByAward($this->session->userdata('award_id'));
				$this->data['award_panelist_chief'] = $this->admin_model->getPanelistByAward($this->session->userdata('award_id'), 'chief');
				if(isset($this->data['award_panelist_data']) && !empty($this->data['award_panelist_data']))
				{
					foreach($this->data['award_panelist_data'] as $temp)
					{
						$this->data['award_panelist_ids'][] = $temp['admin_id'];
					}
				}
				$this->session->set_userdata('award_page', 'create');
				
				$this->load->view('admin/manage_event/create_award',$this->data);
			}
		}
		else{
			$this->session->sess_destroy();
			header('Location: '.BASE_URL.'/login');
			redirect(BASE_URL.'/login');
			exit();
		}
	}

	public function manageAward($value='')
	{
		if($this->session->userdata('admin_id') && $this->session->userdata('admin_id') != '' && $this->session->userdata('logedin'))
		{
			if(!in_array($value, $this->allowed))
			{
				header('Location: '.BASE_URL.'/'.$this->admin.'/dashboard');
				redirect(BASE_URL.'/'.$this->admin.'/dashboard');
				exit();
			}
			$this->data['all_awards']  = $this->event_model->getAllAwards();
			$this->data['award_page'] = 'manage';
			$this->load->view('admin/manage_event/manage_award',$this->data);
		}
		else{
			$this->session->sess_destroy();
			header('Location: '.BASE_URL.'/login');
			redirect(BASE_URL.'/login');
			exit();
		}
	}
	
	public function modifyAward($value='')
	{
		if($this->session->userdata('admin_id') && $this->session->userdata('admin_id') != '' && $this->session->userdata('logedin'))
		{
			$search_data = 'All';
			
			if(!in_array($value, $this->allowed))
			{
				header('Location: '.BASE_URL.'/'.$this->admin.'/dashboard');
				redirect(BASE_URL.'/'.$this->admin.'/dashboard');
				exit();
			}
			
			if($this->input->get('id') && $this->input->get('id') != '' && preg_match('/^[0-9]+$/',$this->input->get('id')))
			{
				if($this->input->get('type') && $this->input->get('type') != '' && preg_match("/^[A-Za-z]+$/",$this->input->get('type')))
				{
					$this->data['get_value'] = $this->input->get();
					if($this->input->get('type') == 'delete')
					{
						$this->event_model->updateAwardStatus($this->input->get('id'), 'Deleted');
						$this->session->set_userdata('award_success', 'Award deleted successfully');
						header('Location: '.BASE_URL.'/'.$this->admin.'/manage_award');
						redirect(BASE_URL.'/'.$this->admin.'/manage_award');
						exit();
					}
					if($this->input->get('type') == 'edit')
					{
						$this->session->set_userdata('edit_award', $this->input->get('id'));
						header('Location: '.BASE_URL.'/'.$this->admin.'/edit_award');
						redirect(BASE_URL.'/'.$this->admin.'/edit_award');
						exit();
					}
				}
				else {
					header('Location: '.BASE_URL.'/'.$this->admin.'/manage_award');
					redirect(BASE_URL.'/'.$this->admin.'/manage_award');
					exit();
				}
			}
			else
			{
				header('Location: '.BASE_URL.'/'.$this->admin.'/manage_award');
				redirect(BASE_URL.'/'.$this->admin.'/manage_award');
				exit();
			}
		}
		else{
			$this->session->sess_destroy();
			header('Location: '.BASE_URL.'/login');
			redirect(BASE_URL.'/login');
			exit();
		}
	}

	public function editAward($value='')
	{
		if($this->session->userdata('admin_id') && $this->session->userdata('admin_id') != '' && $this->session->userdata('logedin'))
		{
			if(!in_array($value, $this->allowed))
			{
				header('Location: '.BASE_URL.'/'.$this->admin.'/dashboard');
				redirect(BASE_URL.'/'.$this->admin.'/dashboard');
				exit();
			}
			
			if($this->input->post('selectevent'))
			{
				// Set validation rules.
				$this->form_validation->set_rules('selectevent', 'Choose Event','trim|required|xss_clean');
				$this->form_validation->set_rules('awardname', 'Award Name','trim|required|xss_clean');
				$this->form_validation->set_rules('description2', 'Award Description','trim|xss_clean');
				$this->form_validation->set_rules('admin_select', 'Admin Incharge','trim|xss_clean|required');
				$this->form_validation->set_rules('cp_select', 'Chief Panelist','trim|xss_clean|required');
				$this->form_validation->set_rules('status_select', 'Award Status','trim|xss_clean');
				$this->form_validation->set_rules('refree_select', 'Award Refree','trim|xss_clean');
				$this->form_validation->set_rules('startdate', 'Start Date', 'regex_match[/^[0-9]{1,2}(\-)+[0-9]{1,2}(\-)+[0-9]{2,4}$/]|xss_clean'); 
				$this->form_validation->set_rules('enddate', 'End Date', 'regex_match[/^[0-9]{1,2}(\-)+[0-9]{1,2}(\-)+[0-9]{2,4}$/]|xss_clean');
				
				if ($this->form_validation->run())
				{
					$this->data['post_value'] = $this->input->post();
					$this->data['post_value']['file'] = $_FILES;
					$this->event_model->updateAward($this->data['post_value']);
					
					$this->session->set_userdata('award_page', 'edit');
					$this->session->set_userdata('award_success', ' Award updated successfully.');
					header('Location: '.BASE_URL.'/'.$this->admin.'/edit_award');
					redirect(BASE_URL.'/'.$this->admin.'/edit_award');
					exit();
				}
				else
				{
					$this->data['post_value'] = $this->input->post();
					$this->data['error'] = validation_errors();
					
					$this->data['all_awards']  = $this->event_model->getAllAwards();
					$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
					$this->data['admin_data'] = $this->admin_model->fetch_admin();
					$this->data['panelist_data'] = $this->admin_model->getPanelistByName('All', '', '');
					$this->data['award_panelist_data'] = $this->admin_model->getPanelistByAward($this->session->userdata('edit_award'));
					$this->data['award_panelist_chief'] = $this->admin_model->getPanelistByAward($this->session->userdata('edit_award'), 'chief');
					if(isset($this->data['award_panelist_data']) && !empty($this->data['award_panelist_data']))
					{
						foreach($this->data['award_panelist_data'] as $temp)
						{
							$this->data['award_panelist_ids'][] = $temp['admin_id'];
						}
					}
					$this->data['criteria_data'] = $this->event_model->getCriteriaById($this->session->userdata('edit_award'));
					$this->session->set_userdata('award_page', 'edit');
					$this->load->view('admin/manage_event/edit_award',$this->data);
				}
			}
			else if($this->input->post('edit_type') && $this->input->post('edit_type') == 'criteria')
			{
				$this->form_validation->set_rules('scopus2', 'Scopus','trim|xss_clean|integer');
				$this->form_validation->set_rules('publication2', 'Publication','trim|xss_clean|integer');
				$this->form_validation->set_rules('journal', 'Journal','trim|xss_clean|integer');
				$this->form_validation->set_rules('patents', 'Patents','trim|xss_clean|integer');
				$this->form_validation->set_rules('conf_pro', 'Conference Proceedings','trim|xss_clean|integer');
				$this->form_validation->set_rules('books', 'Books/Monographs','trim|xss_clean|integer');
				$this->form_validation->set_rules('social2', 'Social Impact','trim|xss_clean|integer');
				$this->form_validation->set_rules('scoring2', 'Scoring Guideline','trim|xss_clean');
				
				$this->form_validation->set_rules('mc1_label', 'More Criteria1','trim|xss_clean');
				$this->form_validation->set_rules('mc1', 'More Criteria1 value','trim|xss_clean|integer');
				$this->form_validation->set_rules('mc2_label', 'More Criteria2','trim|xss_clean');
				$this->form_validation->set_rules('mc1', 'More Criteria2 value','trim|xss_clean|integer');
				$this->form_validation->set_rules('mc3_label', 'More Criteria3','trim|xss_clean');
				$this->form_validation->set_rules('mc1', 'More Criteria3 value','trim|xss_clean|integer');
				
				if ($this->form_validation->run())
				{
					$this->data['post_value'] = $this->input->post();
					$cat = $this->event_model->masterCriteria();
					$this->event_model->updateAwardCriteria($this->data['post_value'], $cat);
					
					$this->data['all_awards']  = $this->event_model->getAllAwards();
					$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
					$this->data['admin_data'] = $this->admin_model->fetch_admin();
					$this->data['panelist_data'] = $this->admin_model->getPanelistByName('All', '', '');
					$this->data['award_panelist_data'] = $this->admin_model->getPanelistByAward($this->session->userdata('edit_award'));
					$this->data['award_panelist_chief'] = $this->admin_model->getPanelistByAward($this->session->userdata('edit_award'), 'chief');
					if(isset($this->data['award_panelist_data']) && !empty($this->data['award_panelist_data']))
					{
						foreach($this->data['award_panelist_data'] as $temp)
						{
							$this->data['award_panelist_ids'][] = $temp['admin_id'];
						}
					}
					$this->data['criteria_data'] = $this->event_model->getCriteriaById($this->session->userdata('edit_award'));
					$this->session->set_userdata('award_page', 'criteria');
					$this->session->set_userdata('award_success', ' Award criteria updated successfully');
					$this->data['post_value'] = $this->event_model->getAwardById($this->session->userdata('edit_award'));
					$this->load->view('admin/manage_event/edit_award',$this->data);
				}
				else
				{
					$this->data['post_value'] = $this->input->post();	
					$this->data['error'] = validation_errors();
					
					$this->data['all_awards']  = $this->event_model->getAllAwards();
					$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
					$this->data['admin_data'] = $this->admin_model->fetch_admin();
					$this->data['panelist_data'] = $this->admin_model->getPanelistByName('All', '', '');
					$this->data['award_panelist_data'] = $this->admin_model->getPanelistByAward($this->session->userdata('edit_award'));
					$this->data['award_panelist_chief'] = $this->admin_model->getPanelistByAward($this->session->userdata('edit_award'), 'chief');
					if(isset($this->data['award_panelist_data']) && !empty($this->data['award_panelist_data']))
					{
						foreach($this->data['award_panelist_data'] as $temp)
						{
							$this->data['award_panelist_ids'][] = $temp['admin_id'];
						}
					}
					$this->data['criteria_data'] = $this->event_model->getCriteriaById($this->session->userdata('edit_award'));
					$this->session->set_userdata('award_page', 'criteria');

					$this->load->view('admin/manage_event/edit_award',$this->data);
				}
			}
			else if($this->input->post('edit_type') && $this->input->post('edit_type') == 'panelist')
			{
				$this->data['post_value'] = $this->input->post();
				$this->event_model->addAwardPanelist($this->data['post_value']);	
				
				$this->data['all_awards']  = $this->event_model->getAllAwards();
				$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
				$this->data['admin_data'] = $this->admin_model->fetch_admin();
				$this->data['panelist_data'] = $this->admin_model->getPanelistByName('All', '', '');
				$this->data['award_panelist_data'] = $this->admin_model->getPanelistByAward($this->session->userdata('edit_award'));
				$this->data['award_panelist_chief'] = $this->admin_model->getPanelistByAward($this->session->userdata('edit_award'), 'chief');
				if(isset($this->data['award_panelist_data']) && !empty($this->data['award_panelist_data']))
				{
					foreach($this->data['award_panelist_data'] as $temp)
					{
						$this->data['award_panelist_ids'][] = $temp['admin_id'];
					}
				}
				$this->data['criteria_data'] = $this->event_model->getCriteriaById($this->session->userdata('edit_award'));
				$this->session->set_userdata('award_page', 'panelist');
				$this->session->set_userdata('award_success', ' Award panelist updated successfully');

				$this->load->view('admin/manage_event/edit_award',$this->data);
			}
			else if($this->session->userdata('edit_award') && $this->session->userdata('edit_award')!='')
			{
				$this->data['all_awards']  = $this->event_model->getAllAwards();
				$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
				$this->data['admin_data'] = $this->admin_model->fetch_admin();
				$this->data['panelist_data'] = $this->admin_model->getPanelistByName('All', '', '');
				$this->data['award_panelist_data'] = $this->admin_model->getPanelistByAward($this->session->userdata('edit_award'));
				$this->data['award_panelist_chief'] = $this->admin_model->getPanelistByAward($this->session->userdata('edit_award'), 'chief');
				$this->data['applicant'] = $this->admin_model->getApplicantBYAward($this->session->userdata('edit_award'));
				if(isset($this->data['award_panelist_data']) && !empty($this->data['award_panelist_data']))
				{
					foreach($this->data['award_panelist_data'] as $temp)
					{
						$this->data['award_panelist_ids'][] = $temp['admin_id'];
					}
				}
				$this->data['criteria_data'] = $this->event_model->getCriteriaById($this->session->userdata('edit_award'));
				$this->session->set_userdata('award_page', 'edit');
				$this->data['post_value'] = $this->event_model->getAwardById($this->session->userdata('edit_award'));
				$this->load->view('admin/manage_event/edit_award',$this->data);
			}	
			else
			{
				header('Location: '.BASE_URL.'/'.$this->admin.'/manage_award');
				redirect(BASE_URL.'/'.$this->admin.'/manage_award');
				exit();
			}
		}
		else{
			$this->session->sess_destroy();
			header('Location: '.BASE_URL.'/login');
			redirect(BASE_URL.'/login');
			exit();
		}
	}

	public function manageEventFaqs($value='')
	{
		if($this->session->userdata('admin_id') && $this->session->userdata('admin_id') != '' && $this->session->userdata('logedin'))
		{
			if(!in_array($value, $this->allowed))
			{
				header('Location: '.BASE_URL.'/'.$this->admin.'/dashboard');
				redirect(BASE_URL.'/'.$this->admin.'/dashboard');
				exit();
			}
			
			if($this->input->get('event') && $this->input->get('event') != '' && preg_match('/^[0-9]+$/',$this->input->get('event')))
			{
				$this->data['event'] = $this->input->get('event');
				$this->data['faq_list'] = $this->event_model->getFaqByEvent($this->input->get('event'));
				$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
				$this->load->view('admin/manage_event/manage_faq',$this->data);
			}
			else if($this->input->post('faq_event')  && $this->input->post('faq_event') != '' && preg_match('/^[0-9]+$/',$this->input->post('faq_event')))
			{
				$this->data['event'] = $this->input->post('faq_event');
				$this->data['faq_id'] = $this->event_model->addEventFaq($this->input->post());
				$this->data['faq_list'] = $this->event_model->getFaqByEvent($this->input->post('faq_event'));
				$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
				$this->load->view('admin/manage_event/manage_faq',$this->data);
			}
			else {
				$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
				$this->load->view('admin/manage_event/manage_faq',$this->data);	
			}
		}
		else{
			$this->session->sess_destroy();
			header('Location: '.BASE_URL.'/login');
			redirect(BASE_URL.'/login');
			exit();
		}
	}
	
	public function modifyFaqs($value='')
	{
		$data = $this->input->get('id');
		if(isset($data) && $data != '' && preg_match('/^[0-9]+$/',$data))
		{
			$this->data['event'] = $this->input->get('event');
			$this->event_model->changeFaqStatus($data, 'Deleted');
			$this->data['faq_list'] = $this->event_model->getFaqByEvent($this->input->get('event'));
			$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
			$this->load->view('admin/manage_event/manage_faq',$this->data);
		}
	}
	
	public function manageEventVideos($value='')
	{
		if($this->session->userdata('admin_id') && $this->session->userdata('admin_id') != '' && $this->session->userdata('logedin'))
		{
			if(!in_array($value, $this->allowed))
			{
				header('Location: '.BASE_URL.'/'.$this->admin.'/dashboard');
				redirect(BASE_URL.'/'.$this->admin.'/dashboard');
				exit();
			}
			
			if($this->input->get('event') && $this->input->get('event') != '' && preg_match('/^[0-9]+$/',$this->input->get('event')))
			{
				$this->data['event'] = $this->input->get('event');
				$this->data['video_list'] = $this->event_model->getVideoByEvent($this->input->get('event'));
				$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
				$this->load->view('admin/manage_event/manage_video',$this->data);
			}
			else if($this->input->post('video_event')  && $this->input->post('video_event') != '' && preg_match('/^[0-9]+$/',$this->input->post('video_event')))
			{
				$this->data['event'] = $this->input->post('video_event');
				$this->data['video_id'] = $this->event_model->addEventVideo($this->input->post());
				$this->data['video_list'] = $this->event_model->getVideoByEvent($this->input->post('video_event'));
				$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
				$this->load->view('admin/manage_event/manage_video',$this->data);
			}
			else {
				$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
				$this->load->view('admin/manage_event/manage_video',$this->data);	
			}
		}
		else{
			$this->session->sess_destroy();
			header('Location: '.BASE_URL.'/login');
			redirect(BASE_URL.'/login');
			exit();
		}
	}
	
	public function modifyVideos($value='')
	{
		$data = $this->input->get('id');
		if(isset($data) && $data != '' && preg_match('/^[0-9]+$/',$data))
		{
			$this->data['event'] = $this->input->get('event');
			$this->event_model->changeVideoStatus($data, 'Deleted');
			$this->data['video_list'] = $this->event_model->getVideoByEvent($this->input->get('event'));
			$this->data['event_data'] = $this->event_model->getEventByName('All', '', '');
			$this->load->view('admin/manage_event/manage_video',$this->data);
		}
	}
	
	//report
	public function report1(){
		if($this->session->userdata('admin_id') && $this->session->userdata('admin_id') != '' && $this->session->userdata('logedin'))
		{
		if($this->input->post()){
			$this->load->model('admin_model');
			$data['admin_details'] = $this->admin_model->report1_search();
			$this->load->view('admin/reports/report1',$data);
			
		}else {
			$this->load->model('admin_model');
			$data['admin_details'] = $this->admin_model->report1();
			$this->load->view('admin/reports/report1',$data);
		}}
		else{
			$this->session->sess_destroy();
			header('Location: '.BASE_URL.'/login');
			redirect(BASE_URL.'/login');
			exit();
		}
		
	}
	public function report2(){
		if($this->session->userdata('admin_id') && $this->session->userdata('admin_id') != '' && $this->session->userdata('logedin'))
		{
		if($this->input->post()){
			$this->load->model('admin_model');
			$data['panelist_details'] = $this->admin_model->report2_search();
			$this->load->view('admin/reports/report2',$data);
			
		}else {
			$this->load->model('admin_model');
			$data['panelist_details'] = $this->admin_model->report2();
			$this->load->view('admin/reports/report2',$data);
		}}
		else{
			$this->session->sess_destroy();
			header('Location: '.BASE_URL.'/login');
			redirect(BASE_URL.'/login');
			exit();
		}
		
	}
	public function report3(){
		if($this->session->userdata('admin_id') && $this->session->userdata('admin_id') != '' && $this->session->userdata('logedin'))
		{
		if($this->input->post()){
			$this->load->model('admin_model');
			$data['event_report'] = $this->admin_model->report3_search();
			for($i=0; $i < count($data['event_report']); $i++){
				$award_incharge_id = $data['event_report'][$i]->award_incharge_id;
				$award_id = $data['event_report'][$i]->award_id;
				$data['award_incharge'][] = $this->admin_model->award_incharge($award_incharge_id);
				$data['award_panelist'][] = $this->admin_model->award_panelist($award_id);
				$data['total_applicant'][] = count($this->admin_model->total_applicant($award_id));
				$data['total_panelist'][] = count($this->admin_model->total_panelist($award_id));
			}
			$this->load->view('admin/reports/report3',$data);
			
		}else {
			$this->load->model('admin_model');
			$data['event_report'] = $this->admin_model->event_report();
			for($i=0; $i < count($data['event_report']); $i++){
				$award_incharge_id = $data['event_report'][$i]->award_incharge_id;
				$award_id = $data['event_report'][$i]->award_id;
				$data['award_incharge'][] = $this->admin_model->award_incharge($award_incharge_id);
				$data['award_panelist'][] = $this->admin_model->award_panelist($award_id,'Chief Panelist');
				$data['total_applicant'][] = count($this->admin_model->total_applicant($award_id));
				$data['total_panelist'][] = count($this->admin_model->total_panelist($award_id));
			}
			$this->load->view('admin/reports/report3',$data);
		}}
		else{
			$this->session->sess_destroy();
			header('Location: '.BASE_URL.'/login');
			redirect(BASE_URL.'/login');
			exit();
		}
	}
	
	public function report4(){
		if($this->session->userdata('admin_id') && $this->session->userdata('admin_id') != '' && $this->session->userdata('logedin'))
		{
		/*if($this->input->post()){
			$data['searchEvent'] = $this->admin_model->searchByevent();
			for($i=0; $i<count($data['searchEvent']); $i++){
				$id = $data['searchEvent'][$i]->event_id;
				$data['award_data'] = $this->admin_model->awardByevent($id);
				var_dump($data['award_data']); die();
				$this->admin_model->getPanelistbyId();
			}
			
			}
			*/
		
		/*else {*/
			$this->load->model('admin_model');
			$data['panelist_deatail'] = $this->admin_model->getAllpnelist();
			for($i=0; $i<count($data['panelist_deatail']); $i++){
				$award_id = $data['panelist_deatail'][$i]->award_panelist_award_id;
				$data['event_award'][] = $this->admin_model->event_award($award_id);
			}$this->load->view('admin/reports/report4',$data);
			}
		else{
			$this->session->sess_destroy();
			header('Location: '.BASE_URL.'/login');
			redirect(BASE_URL.'/login');
			exit();
		}
			
	//	}
	}
	
	public function report5(){
		if($this->session->userdata('admin_id') && $this->session->userdata('admin_id') != '' && $this->session->userdata('logedin'))
		{
			$this->load->model('admin_model');
			$data['applicantBYEvent'] = $this->admin_model->applicantBY_Event();
			for($i=0; $i<count($data['applicantBYEvent']); $i++){
				$data['total_applicant'][$i] = $this->admin_model->total_applicantByEvent($data['applicantBYEvent'][$i]->award_id);
				$data['applicantBycountry'][$i] = $this->admin_model->applicantBycountry($data['applicantBYEvent'][$i]->award_id);
			}
			$this->load->view('admin/reports/report5',$data);
		}
		else{
			$this->session->sess_destroy();
			header('Location: '.BASE_URL.'/login');
			redirect(BASE_URL.'/login');
			exit();
		}
	}
	
	public function report6(){
		if($this->session->userdata('admin_id') && $this->session->userdata('admin_id') != '' && $this->session->userdata('logedin'))
		{
			$data['winner'] = $this->admin_model->Getwinner();
			$this->load->view('admin/reports/report6',$data);
		}
		else{
			$this->session->sess_destroy();
			header('Location: '.BASE_URL.'/login');
			redirect(BASE_URL.'/login');
			exit();
		}
	}
	
	public function download_report1(){
		if($this->session->userdata('admin_id') && $this->session->userdata('admin_id') != '' && $this->session->userdata('logedin'))
		{
			$this->load->model('admin_model');
			$admin_details = $this->admin_model->report1();
			define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
	
			$this->load->library('PHPExcel');
			
			// Create new PHPExcel object
			$objPHPExcel = new PHPExcel();
			
			// Create a first sheet
			$objPHPExcel->setActiveSheetIndex(0);
			$objPHPExcel->getActiveSheet()->setCellValue('A1', "S.No.");
			$objPHPExcel->getActiveSheet()->setCellValue('B1', "Full Name");
			$objPHPExcel->getActiveSheet()->setCellValue('C1', "Email");
			$objPHPExcel->getActiveSheet()->setCellValue('D1', "Contact");
			
			// Freeze panes
			$objPHPExcel->getActiveSheet()->freezePane('A2');
		
		// Add data
		$row = 2;
			$col = 0;
			$i=0;
			foreach ($admin_details as $value) {
				//if($col == 0){
					$value1 = $row-1;
					//$col++;
					if(isset($value1)) {
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value1);
					}
					$col++;
					if(isset($value['admin_fullname'])){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value['admin_fullname']);
					}
					$col++;
					if(isset($value['admin_email'])){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value['admin_email']);
					}
					$col++;
					if(isset($value['admin_contact_number'])){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value['admin_contact_number']);
					}
					$col++;
					
				$col = 0;
				$row++;
				$i++;
			}
			// Set active sheet index to the first sheet, so Excel opens this as the first sheet
			$objPHPExcel->setActiveSheetIndex(0);
			// Redirect output to a client’s web browser (Excel5)
			header('Content-Type: application/vnd.ms-excel');
			header('Content-Disposition: attachment;filename="Admin_List_Report"'.date('d-M-Y').'".xls"');
			header('Cache-Control: max-age=0');
			// If you're serving to IE 9, then the following may be needed
			header('Cache-Control: max-age=1');
			
			// If you're serving to IE over SSL, then the following may be needed
			header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
			header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
			header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
			header ('Pragma: public'); // HTTP/1.0
			
			$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
			$objWriter->save('php://output');
			exit;	
			}
		else{
			$this->session->sess_destroy();
			header('Location: '.BASE_URL.'/login');
			redirect(BASE_URL.'/login');
			exit();
		}
	}
	
	public function download_report2(){
		if($this->session->userdata('admin_id') && $this->session->userdata('admin_id') != '' && $this->session->userdata('logedin'))
		{
		$this->load->model('admin_model');
			$panelist_details = $this->admin_model->report2();
			define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
	
			$this->load->library('PHPExcel');
			
			// Create new PHPExcel object
			$objPHPExcel = new PHPExcel();
			
			// Create a first sheet
			$objPHPExcel->setActiveSheetIndex(0);
			$objPHPExcel->getActiveSheet()->setCellValue('A1', "S.No.");
			$objPHPExcel->getActiveSheet()->setCellValue('B1', "Full Name");
			$objPHPExcel->getActiveSheet()->setCellValue('C1', "Affiliation");
			$objPHPExcel->getActiveSheet()->setCellValue('D1', "Email");
			$objPHPExcel->getActiveSheet()->setCellValue('E1', "Contact");
			
			// Freeze panes
			$objPHPExcel->getActiveSheet()->freezePane('A2');
		
		// Add data
		$row = 2;
			$col = 0;
			$i=0;
			foreach ($panelist_details as $value) {
				//if($col == 0){
					$value1 = $row-1;
					//$col++;
					if(isset($value1)) {
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value1);
					}
					$col++;
					if(isset($value['admin_fullname'])){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value['admin_fullname']);
					}
					$col++;
					if(isset($value['admin_affiliation'])){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value['admin_affiliation']);
					}
					$col++;
					if(isset($value['admin_email'])){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value['admin_email']);
					}
					$col++;
					if(isset($value['admin_contact_number'])){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value['admin_contact_number']);
					}
					$col++;
					
				$col = 0;
				$row++;
				$i++;
			}
			// Set active sheet index to the first sheet, so Excel opens this as the first sheet
			$objPHPExcel->setActiveSheetIndex(0);
			// Redirect output to a client’s web browser (Excel5)
			header('Content-Type: application/vnd.ms-excel');
			header('Content-Disposition: attachment;filename="Panelist_Report"'.date('d-M-Y').'".xls"');
			header('Cache-Control: max-age=0');
			// If you're serving to IE 9, then the following may be needed
			header('Cache-Control: max-age=1');
			
			// If you're serving to IE over SSL, then the following may be needed
			header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
			header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
			header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
			header ('Pragma: public'); // HTTP/1.0
			
			$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
			$objWriter->save('php://output');
			exit;	
			}
		else{
			$this->session->sess_destroy();
			header('Location: '.BASE_URL.'/login');
			redirect(BASE_URL.'/login');
			exit();
		}
	}
	
	public function download_report3(){
		if($this->session->userdata('admin_id') && $this->session->userdata('admin_id') != '' && $this->session->userdata('logedin'))
		{
		$event_report = $this->admin_model->event_report();
			for($i=0; $i < count($event_report); $i++){
				$award_incharge_id = $event_report[$i]->award_incharge_id;
				$award_id = $event_report[$i]->award_id;
				$award_incharge[] = $this->admin_model->award_incharge($award_incharge_id);
				$award_panelist[] = $this->admin_model->award_panelist($award_id,'Chief Panelist');
				$total_applicant[] = count($this->admin_model->total_applicant($award_id));
				$total_panelist[] = count($this->admin_model->total_panelist($award_id));
			}
			define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
	
			$this->load->library('PHPExcel');
			
			// Create new PHPExcel object
			$objPHPExcel = new PHPExcel();
			
			// Create a first sheet
			$objPHPExcel->setActiveSheetIndex(0);
			$objPHPExcel->getActiveSheet()->setCellValue('A1', "S.No.");
			$objPHPExcel->getActiveSheet()->setCellValue('B1', "Event Name");
			$objPHPExcel->getActiveSheet()->setCellValue('C1', "Award Name");
			$objPHPExcel->getActiveSheet()->setCellValue('D1', "Chief Panelist");
			$objPHPExcel->getActiveSheet()->setCellValue('E1', "Admin Incharge");
			$objPHPExcel->getActiveSheet()->setCellValue('F1', "No. of Panelist");
			$objPHPExcel->getActiveSheet()->setCellValue('G1', "No. of Applicant");
			$objPHPExcel->getActiveSheet()->setCellValue('H1', "Status");
			$objPHPExcel->getActiveSheet()->setCellValue('I1', "Created Date & Time");
			
			// Freeze panes
			$objPHPExcel->getActiveSheet()->freezePane('A2');
		
		// Add data
		$row = 2;
			$col = 0;
			$i=0;
			foreach ($event_report as $value) {
				//if($col == 0){
					$value1 = $row-1;
					if(isset($value1)) {
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value1);
					}
					$col++;
					if(isset($value->event_name)){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value->event_name);
					}
					$col++;
					if(isset($value->award_name)){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value->award_name);
					}
					$col++;
					if(isset($award_panelist[$i][0]->admin_fullname)){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $award_panelist[$i][0]->admin_fullname);
					}
					$col++;
					if(isset($award_incharge[$i][0]->admin_fullname)){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $award_incharge[$i][0]->admin_fullname);
					}
					$col++;
					if(isset($total_panelist[$i])){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $total_panelist[$i]);
					}
					$col++;
					if(isset($total_applicant[$i])){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $total_applicant[$i]);
					}
					$col++;
					if(isset($value->award_current_status)){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value->award_current_status);
					}
					$col++;
					if(isset($value->award_created_date)) {
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value->award_created_date);
					}
					
			//	$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, htmlspecialchars_decode($value,ENT_QUOTES));
			$col = 0;
			$row++;
			$i++;
			}
			
			// Set active sheet index to the first sheet, so Excel opens this as the first sheet
			$objPHPExcel->setActiveSheetIndex(0);
			// Redirect output to a client’s web browser (Excel5)
			header('Content-Type: application/vnd.ms-excel');
			header('Content-Disposition: attachment;filename="Event_Summary_Report"'.date('d-M-Y').'".xls"');
			header('Cache-Control: max-age=0');
			// If you're serving to IE 9, then the following may be needed
			header('Cache-Control: max-age=1');
			
			// If you're serving to IE over SSL, then the following may be needed
			header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
			header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
			header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
			header ('Pragma: public'); // HTTP/1.0
			
			$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
			$objWriter->save('php://output');
			exit;	
			}
		else{
			$this->session->sess_destroy();
			header('Location: '.BASE_URL.'/login');
			redirect(BASE_URL.'/login');
			exit();
		}
	}
	
	public function download_report4(){
		if($this->session->userdata('admin_id') && $this->session->userdata('admin_id') != '' && $this->session->userdata('logedin'))
		{
		$this->load->model('admin_model');
			$panelist_deatail = $this->admin_model->getAllpnelist();
			for($i=0; $i<count($panelist_deatail); $i++){
				$award_id = $panelist_deatail[$i]->award_panelist_award_id;
				$event_award[] = $this->admin_model->event_award($award_id);
			}
			define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
	
			$this->load->library('PHPExcel');
			
			// Create new PHPExcel object
			$objPHPExcel = new PHPExcel();
			
			// Create a first sheet
			$objPHPExcel->setActiveSheetIndex(0);
			$objPHPExcel->getActiveSheet()->setCellValue('A1', "S.No.");
			$objPHPExcel->getActiveSheet()->setCellValue('B1', "Event Name");
			$objPHPExcel->getActiveSheet()->setCellValue('C1', "Award Name");
			$objPHPExcel->getActiveSheet()->setCellValue('D1', "Event Status");
			$objPHPExcel->getActiveSheet()->setCellValue('E1', "Panelist Name");
			$objPHPExcel->getActiveSheet()->setCellValue('F1', "Is Chief");
			$objPHPExcel->getActiveSheet()->setCellValue('G1', "Email");
			$objPHPExcel->getActiveSheet()->setCellValue('H1', "Contact");
			
			// Freeze panes
			$objPHPExcel->getActiveSheet()->freezePane('A2');
		
		// Add data
		$row = 2;
			$col = 0;
			$i=0;
			foreach ($panelist_deatail as $value) {
					$value1 = $row-1;
					if(isset($value1)) {
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value1);
					}
					$col++;
					if(isset($event_award[$i][0]->event_name)){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $event_award[$i][0]->event_name);
					}
					$col++;
					if(isset($event_award[$i][0]->award_name)){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $event_award[$i][0]->award_name);
					}
					$col++;
					if(isset($event_award[$i][0]->award_current_status)){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $event_award[$i][0]->award_current_status);
					}
					$col++;
					if(isset($value->admin_fullname)){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value->admin_fullname);
					}
					$col++;
					if(isset($value->award_panelist_type)){
						if($value->award_panelist_type=='Chief Panelist'){
							$v = "True";
						}else {
							$v = "False";
						}
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $v);
					}
					$col++;
					if(isset($value->admin_email)){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value->admin_email);
					}
					$col++;
					if(isset($value->admin_contact_number)){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value->admin_contact_number);
					}
					$col++;
				$col = 0;
				$row++;
				$i++;
			}
			// Set active sheet index to the first sheet, so Excel opens this as the first sheet
			$objPHPExcel->setActiveSheetIndex(0);
			// Redirect output to a client’s web browser (Excel5)
			header('Content-Type: application/vnd.ms-excel');
			header('Content-Disposition: attachment;filename="Panelist_list_by_Event_Report"'.date('d-M-Y').'".xls"');
			header('Cache-Control: max-age=0');
			// If you're serving to IE 9, then the following may be needed
			header('Cache-Control: max-age=1');
			
			// If you're serving to IE over SSL, then the following may be needed
			header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
			header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
			header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
			header ('Pragma: public'); // HTTP/1.0
			
			$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
			$objWriter->save('php://output');
			exit;	
		}
		else{
			$this->session->sess_destroy();
			header('Location: '.BASE_URL.'/login');
			redirect(BASE_URL.'/login');
			exit();
		}
	}
	
	public function download_report5(){
		if($this->session->userdata('admin_id') && $this->session->userdata('admin_id') != '' && $this->session->userdata('logedin'))
		{
		$this->load->model('admin_model');
			$applicantBYEvent = $this->admin_model->applicantBY_Event();
			for($i=0; $i<count($applicantBYEvent); $i++){
				$total_applicant[$i] = $this->admin_model->total_applicantByEvent($applicantBYEvent[$i]->award_id);
				$applicantBycountry[$i] = $this->admin_model->applicantBycountry($applicantBYEvent[$i]->award_id);
			}
			define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
	
			$this->load->library('PHPExcel');
			
			// Create new PHPExcel object
			$objPHPExcel = new PHPExcel();
			
			// Create a first sheet
			$objPHPExcel->setActiveSheetIndex(0);
			$objPHPExcel->getActiveSheet()->setCellValue('A1', "S.No.");
			$objPHPExcel->getActiveSheet()->setCellValue('B1', "Event Name");
			$objPHPExcel->getActiveSheet()->setCellValue('C1', "Award Name");
			$objPHPExcel->getActiveSheet()->setCellValue('D1', "Total Applicant");
			$objPHPExcel->getActiveSheet()->setCellValue('E1', "Total Applicant by Country");
			$objPHPExcel->getActiveSheet()->setCellValue('F1', "Status");
			
			// Freeze panes
			$objPHPExcel->getActiveSheet()->freezePane('A2');
		
		// Add data
		$row = 2;
			$col = 0;
			$i=0;
			foreach ($applicantBYEvent as $value) {
				//if($col == 0){
					$value1 = $row-1;
					//$col++;
					if(isset($value1)) {
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value1);
					}
					$col++;
					if(isset($value->event_name)){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value->event_name);
					}
					$col++;
					if(isset($value->award_name)){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value->award_name);
					}
					$col++;
					if(isset($total_applicant[$i])){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $total_applicant[$i]);
					}
					$col++;
					if(isset($applicantBycountry[$i][0]->country_name)){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $applicantBycountry[$i][0]->country_name.':'.$applicantBycountry[$i][0]->total);
					}
					$col++;
					if(isset($value->award_current_status)){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value->award_current_status);
					}
					$col++;
					
				$col = 0;
				$row++;
				$i++;
			}
			// Set active sheet index to the first sheet, so Excel opens this as the first sheet
			$objPHPExcel->setActiveSheetIndex(0);
			// Redirect output to a client’s web browser (Excel5)
			header('Content-Type: application/vnd.ms-excel');
			header('Content-Disposition: attachment;filename="Application_Summary_by_Event_Report"'.date('d-M-Y').'".xls"');
			header('Cache-Control: max-age=0');
			// If you're serving to IE 9, then the following may be needed
			header('Cache-Control: max-age=1');
			
			// If you're serving to IE over SSL, then the following may be needed
			header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
			header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
			header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
			header ('Pragma: public'); // HTTP/1.0
			
			$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
			$objWriter->save('php://output');
			exit;	
		}
		else{
			$this->session->sess_destroy();
			header('Location: '.BASE_URL.'/login');
			redirect(BASE_URL.'/login');
			exit();
		}
	}
	
	public function download_report6(){
		if($this->session->userdata('admin_id') && $this->session->userdata('admin_id') != '' && $this->session->userdata('logedin'))
		{
		$this->load->model('admin_model');
			$winner = $this->admin_model->Getwinner();
			define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
	
			$this->load->library('PHPExcel');
			
			// Create new PHPExcel object
			$objPHPExcel = new PHPExcel();
			
			// Create a first sheet
			$objPHPExcel->setActiveSheetIndex(0);
			$objPHPExcel->getActiveSheet()->setCellValue('A1', "S.No.");
			$objPHPExcel->getActiveSheet()->setCellValue('B1', "Event Name");
			$objPHPExcel->getActiveSheet()->setCellValue('C1', "Award Name");
			$objPHPExcel->getActiveSheet()->setCellValue('D1', "Winner");
			$objPHPExcel->getActiveSheet()->setCellValue('E1', "Rank");
			$objPHPExcel->getActiveSheet()->setCellValue('F1', "Current Affiliation");
			
			// Freeze panes
			$objPHPExcel->getActiveSheet()->freezePane('A2');
		
		// Add data
		$row = 2;
			$col = 0;
			$i=0;
			foreach ($winner as $value) {
				//if($col == 0){
					$value1 = $row-1;
					//$col++;
					if(isset($value1)) {
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value1);
					}
					$col++;
					if(isset($value['Event'])){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value['Event']);
					}
					$col++;
					if(isset($value['Award'])){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value['Award']);
					}
					$col++;
					if(isset($value['Winner'])){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value['Winner']);
					}
					$col++;
					if(isset($value['Rank'])){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value['Rank']);
					}
					$col++;
					if(isset($value['Affiliation'])){
						$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value['Affiliation']);
					}
					$col++;
					
				$col = 0;
				$row++;
				$i++;
			}
			// Set active sheet index to the first sheet, so Excel opens this as the first sheet
			$objPHPExcel->setActiveSheetIndex(0);
			// Redirect output to a client’s web browser (Excel5)
			header('Content-Type: application/vnd.ms-excel');
			header('Content-Disposition: attachment;filename="Winner_by_Event_Report"'.date('d-M-Y').'".xls"');
			header('Cache-Control: max-age=0');
			// If you're serving to IE 9, then the following may be needed
			header('Cache-Control: max-age=1');
			
			// If you're serving to IE over SSL, then the following may be needed
			header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
			header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
			header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
			header ('Pragma: public'); // HTTP/1.0
			
			$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
			$objWriter->save('php://output');
			exit;	
		}
		else{
			$this->session->sess_destroy();
			header('Location: '.BASE_URL.'/login');
			redirect(BASE_URL.'/login');
			exit();
		}
	}
	
	
}
/* End of file manage_event.php */
/* Location: ./application/controllers/manage_event.php */
?>